By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,842 Members | 2,154 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,842 IT Pros & Developers. It's quick & easy.

Find index of an array item on a form

P: 7
I have a table on a form containing 2 columns - size type and size. Depending on the size type (Mens, womens, Youth) I want to change the set of sizes available (in an option box). I have been able to do this (in Mozilla - haven't tested in IE yet) for a single row, and have been able to set the size list for an indexed row but cannot figure out how to tell on which row the size type has been changed.
My function follows : (when I set j = 1, I do set the size options for the 2nd row but I want to set j according to which "item" has been changed)

Expand|Select|Wrap|Line Numbers
  1. function setsize(item){
  2.   var c = item.value;
  3.   var j = item.index;    ### this statement does not work - is there a way to set j correctly?
  4.   if (c == "W") {
  5.   document.indiv.size[j].options[1].text = "X-Small";
  6.   document.indiv.size[j].options[2].text = "Small";
  7.   document.indiv.size[j].options[3].text = "Medium";
  8.   document.indiv.size[j].options[4].text = "Large";
  9.   document.indiv.size[j].options[5].text = "X-Large";
  10. }
  11.   else if (c == "M") {
  12.   document.indiv.size[j].options[1].text = "Small";
  13.   document.indiv.size[j].options[2].text = "Medium";
  14.   document.indiv.size[j].options[3].text = "Large";
  15.   document.indiv.size[j].options[4].text = "X-Large";
  16.   document.indiv.size[j].options[5].text = "XX-Large";}
  17. else if (c == "Y") {
  18.   document.indiv.size[j].options[1].text = "Youth - 8";
  19.   document.indiv.size[j].options[2].text = "Youth - 10 ";
  20.   document.indiv.size[j].options[3].text = "Youth - 12";
  21.   document.indiv.size[j].options[4].text = "Youth - 14";
  22.   document.indiv.size[j].options[5].text = "Youth - 16";}
  23.   }
My form elements and call to the function:
[HTML]<td><select name="sizeType" onchange = "setsize(this)";>
<option value="0" selected>select</option>
<option value="M" > Mens</option>
<option value="W" > Womens </option>
<option value="Y" > Youth </option>
</select></td>
<td><select name="size">
<option value="0" selected> select</option>
<option value="1" display="none"> Small</option>
<option value="2" display="none"> Medium</option>
<option value="3" display="none"> Large</option>
<option value="4" display="none"> X-Large</option>
<option value="5" display="none"> XX-Large</option>
</select></td>[/HTML]
At this point I am just working in html and repeat this row. In Perl it would be in a for loop.

Thanks in advance. Help from this forum has always been useful.
Mar 25 '08 #1
Share this Question
Share on Google+
1 Reply


hsriat
Expert 100+
P: 1,654
This is actually not the right approach.
See this example.
Mar 25 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.