• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Changing options(contents) of a select element in Struts' jsp form

 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a jsp form used in the struts architecture.
The condensed jsp code is given below:



What I want: When i change the 'product' select(drop down box) value from 'Mortgage Protection' to 'Term Assurance', the option in the 'CoverType' select should also change. I want the CoverType drop down to have option value 'Dual' to change to 'Joint'.
So does it mean I remove the 2nd option and add a new option 'joint' ? but again i want when user selects 'Mortgage Protection' , the 'Joint' option should change back to 'Dual'.
Secondly , say the user had chosen 'Dual' and then he changed the 'product' select value to 'Mortgage Protection' . now in 'Mortgage Protection' there is no 'Dual' option , so the 'CoverType' select is reset to have the 'Single' option selected. Infact for each 'product' selection change the 'CoverType' select is reset to select 'Single'.
I guess I have to use a javascript like:


But What I should write in the javascript. Please give me the code or script to do this.
Tanveer
[ August 18, 2004: Message edited by: Tanveer Rameez ]
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
js is:


html (select) is:



hope this helps
 
Tanveer Rameez
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
thankx for the reply. Actually, this is not what I want.
Let me explain with another simpler example:
I have one 'account' select property with options 'saving' and 'corporate'. Initially the 'saving' option will be selected by default.

There is another select with property 'accountType' with options 'single' and 'non-single' (whose display value is 'joint'). 'single' option is selected by default.

So the code will be


Now when I change selection of 'saving' option to 'corporate' option in the 'accounts' select item,
in the 'accountType' select item, the display value of 'non-single' option becomes 'dual' from 'joint'.
That is when the 'account' is 'saving' in the first drop down box, user can see 'single' and 'joint' in the second drop down box. when user chooses 'corporate' in the first drop down box, he can see 'single' and 'dual' in the second drop down box.
So the display word 'joint' has been replaced with 'dual' in the second option in the 'accountType' select item, while the first option 'single' remains unchanged .
the Vice versa will occur when he chooses 'saving' from 'corporate' in the first select item, i.e. the 'dual' word will change to 'joint'.

Hope this explains my need in more detail
Tanveer
[ August 18, 2004: Message edited by: Tanveer Rameez ]
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this:

function doStuff(obj)
{
obj = document.forms[0].account;
var firstSelectValue = obj.options[obj.selectedIndex].value;
if(firstSelectValue == 'corporate')
{
document.forms[0].accountType.options[1].text ='dual';
}
else
{
document.forms[0].accountType.options[1].text ='joint';
}
}

 
Tanveer Rameez
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jason,
that's what I wanted .
Tanveer
[ August 20, 2004: Message edited by: Tanveer Rameez ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic