angrycat Posted November 8, 2005 Share Posted November 8, 2005 Hello All,I have a problem with the following function in Firefox, it works in Explorer, but I am not sure that it should.... function MM_setRowValues(row, state){ for ( i = 1; i <= <%= slotsPerHour %>; i ++ ) { var mField = "f" + row + i; document.setCal(mField).selectedIndex = state; }// end loop}// end function setCal is the literal name of the form, mField is a variable holding the name of a drop down list within the form (setCal).The problem I am having is getting the variable mField into the the line document.setCal(mField).selectedIndex = state; Mozilla reports that it cannot find the function setCal(mField), which is logical as, with the parameters it looks like a function, but I have tried every other permiatation I can think of and nothing works.In short, can I replace the literal value for a listName with a variable:document.formName.listName.selectetIndex Any help appreciated Link to comment Share on other sites More sharing options...
hacknsack Posted November 8, 2005 Share Posted November 8, 2005 You can use the form's element name as a string:http://javascriptkit.com/jsref/elements.shtmlLike: <script type="text/javascript">function MM_setRowValues(row, state){for ( i = 1; i <= 2; i ++ ){ var mField = "f" + row + i; document.forms['setCal'].elements[mField].selectedIndex = state; }// end loop}// end function</script> </head><body onload="MM_setRowValues(0, 1)"><form name="setCal"><table><tr> <td> <select name="f01"> <option value="">Pick One <option value="c1">C1 </select> </td> <td> <select name="f02"> <option value="">Pick One <option value="c1">C1 </select> </td></tr></table></form> Thanks, Link to comment Share on other sites More sharing options...
MadPotato Posted November 8, 2005 Share Posted November 8, 2005 if you want to change the selection of a <select>, try something like document.getElementById("yourSelect")["optionIndex"].selected = true do a loop to do it in every indexhope I helped Link to comment Share on other sites More sharing options...
angrycat Posted November 8, 2005 Author Share Posted November 8, 2005 Thanks for the replies, all working now!! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now