Jump to content


Photo

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


  • Please log in to reply
No replies to this topic

#1 Humpty

Humpty
  • Members
  • PipPipPip
  • Advanced Member
  • 132 posts

Posted 17 August 2006 - 06:10 AM

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:
<input onChange="ChangeRadios('<? echo"$i" ?>');" name="SetRetailPrice<? echo "$i" ?>" type="text" class="ProductOrderNumberBox" value="<? echo"$DPrice" ?>" size="8">

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

The JS Function:
function ChangeRadios(TheID_ofTheItem) { 
var Radio2Select = "mkPerform" + TheID_ofTheItem;
document.AdminForm.Radio2Select[14]
}


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.




SOLUTION:
document.getElementsByName(Radio2Select)[4].checked = 'true';

I have also change it from onchange to onclick.  ...was more appropriate for the job at hand.
- Humpty
  #> Where does the light go when it goes out?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users