Humpty Posted August 17, 2006 Share Posted August 17, 2006 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;document.AdminForm.Radio2Select[14]} [/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.SOLUTION:[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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.