469,344 Members | 5,505 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,344 developers. It's quick & easy.

Find index of an array item on a form

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
1 2323
hsriat
1,654 Expert 1GB
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.

Similar topics

3 posts views Thread by Poewood | last post: by
reply views Thread by Popoxinhxan | last post: by
9 posts views Thread by tshad | last post: by
4 posts views Thread by e_matthes | last post: by
30 posts views Thread by =?Utf-8?B?VGhvbWFzVDIy?= | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.