• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting value from combobox

 
Rebecca Abraham
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have 2 combo boxes - one for fruits & the other for colour. When a fruit is selected, the selected value is to be used to populate the 2nd combo displaying colours. I have created a custom tag <fruit> which takes the fruitId and displays the colours stored in the database. But I'm unable to get the selected value of fruit from the 1st combo. Could someone please help? My code is as follows:

<td align="left" valign="top">
<html:select onchange="redirect(this.options.selectedIndex);" property="fruitId">
<html: option value="1">Apple</html: option>
<html: option value="2">Grapes</html: option>
</html:select>
</td>
<td align="left" valign="top">
<html:select property="colourId">
<fruit:colours fruitId=? />
</html:select>
</td>

Thanks.

Rebecca

[ August 10, 2004: Message edited by: Rebecca Abraham ]
[ August 10, 2004: Message edited by: Rebecca Abraham ]
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rebecca,

The correct syntax for the bit of JavaScript you appear to be trying to write in the onchange event handler is:

where i is the index of your form (I'm assuming you have just one, so probably 0) and j is the index of your select element within your form. I find that naming the elements makes the code clearer and easier to write.

I can't tell you if that will work as I have no experience with Struts. Perhaps you'd have more joy in the Web App Frameworks (Struts) forum.

The thought of a JSP to tell you the colours of fruits made me smile, btw.

Jules
[ August 11, 2004: Message edited by: Julian Kennedy ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!