Jump to content


This topic is now archived and is closed to further replies.


Assign Value to Radio Array (should be easy for someone who knows

Recommended Posts

RESOLVED:  (I have resolved this myself already, please if possible mark this post as completed or resolved / solved ....see the bottom for the solution)

G'day People.

I have an array of 5 radio buttons (or elements) and I wish to change the 'checked' value (or state) for index #4 to true and the 'checked' value (or state) for all others to false when a user changes a text box.

The biggest problem is the # of arrays is a variable.  anywhere fro 1 array of 5 radio's to 700 arrays of 5 radios so I can't statically code the name of the array.  (however I do know the name of the arrays).

This is the page layout:  (RB = Radio,   TB = Text Field)  (these are all in the 1 form by the way)
RB RB RB RB TB RB      (that is the first the radios are all named 'mkPerform0'....then some more stuff then repeated)

RB RB RB RB TB RB      (that is the first the radios are all named 'mkPerform1')

RB RB RB RB TB RB      (that is the first the radios are all named 'mkPerform2') ...and so on for up to 700 times.

The code i have is as follows:
The TextField:
[code]<input onChange="ChangeRadios('<? echo"$i" ?>');" name="SetRetailPrice<? echo "$i" ?>" type="text" class="ProductOrderNumberBox" value="<? echo"$DPrice" ?>" size="8">[/code]

In striaght HTML without the PHP that equates to:
[code]<input onChange="ChangeRadios('2');" name="SetRetailPrice2" type="text" class="ProductOrderNumberBox" value="120" size="8">[/code]

The JS Function:
[code]function ChangeRadios(TheID_ofTheItem) {
var Radio2Select = "mkPerform" + TheID_ofTheItem;
} [/code]

The problem I have here is trying to use that variable where an element name should be.

I have considered giving each individual radio an ID and using the getElementById()  ....not that I really know what I am doing.

Basically what I want is a way to do this.  I have all the info i need and can pass it through I just need JS to accept the variable for the elements name and a way to make it change the radio i want to a checked value.

[code]document.getElementsByName(Radio2Select)[4].checked = 'true';[/code]

I have also change it from onchange to onclick.  ...was more appropriate for the job at hand.

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.