Jump to content

how set selection in select element when the name has ”[]”


Betty_S

Recommended Posts

how set selection in select element when the name has ”[]”Hi folks,I wrote:

<form name=" formname "><select name=" dropdownboxname[]" class="inputbox" size="0" mosreq="0" moslabel="השכלה">	<option value=""> </option>	<option value="x" id="228">תיכון</option>	<option value="y" id="228">על-תיכוני</option>	<option value="z" id="228">תעודה</option></select><input type="text" name="txt" size="20px" value="aaaaaaaa" /></form><script>...for (var i=0; i < document.formname.dropdownboxname.length; i++) {if (document.formname.dropdownboxname[i].value == “value”) {document.formname.dropdownboxname[i].selected = true;}}…

It doesn’t set the selection because the name of the dropdown: If it was without the “[]” then there is no problem, but I must use the “[]”So how can I selection in a dropdownboxname[]Thanks.

Link to comment
Share on other sites

Try this.... [it checks for option value=y and sets it as selected]

<script type="text/javascript">function test() {  var i;  eval("var temp=document.getElementById('dropdownboxname[]');");  alert(temp.length);  for (i=0;i<temp.length;i++) {if (temp[i].value=="y") {temp[i].selected=true;} }}</script></head><body onload="test();"><form name="formname"><select id="dropdownboxname[]" class="inputbox">	<option value=""> </option>	<option value="x" id="228">?????</option>	<option value="y" id="228">??-??????</option>	<option value="z" id="228">?????</option></select>

Link to comment
Share on other sites

Correct me if I am wrong but isn't it possible to reference it like this?

document.formname.elements["dropdownboxname[]"]

?If you want to make an option selected just do this:

document.getElementById("228").selected = 'true'

But first you'll have to fix up the id's on those option tags because an id can only be used once per page.:)

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...