Jump to content

Passing parameter to selectedIndex


angrycat

Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...