This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Changing options(contents) of a select element in Struts' jsp form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Changing options(contents) of a select element in Struts Watch "Changing options(contents) of a select element in Struts New topic
Author

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

Tanveer Rameez
Ranch Hand

Joined: Dec 11, 2000
Posts: 158
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 ]

Author of JPhotoBrush Pro (www.jphotobrushpro.com)
Tausif Khanooni
Ranch Hand

Joined: Nov 14, 2002
Posts: 107
hi
js is:


html (select) is:



hope this helps


"Walking on water and building IT Architecture from <br />specification are easy if and only if both are frozen"
Tanveer Rameez
Ranch Hand

Joined: Dec 11, 2000
Posts: 158
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 ]
Jason Hunt
Ranch Hand

Joined: Sep 09, 2002
Posts: 51
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';
}
}



SCJP, SCWCD, SCBCD, SCDJWS, OCA9i,<br />IBM Certified WAS5.0 Admin<br />IBM Certified Solution Developer - WebSphere Studio 5.0<br />IBM Certified Solution Developer - XML and related Technologies
Tanveer Rameez
Ranch Hand

Joined: Dec 11, 2000
Posts: 158
Thanks Jason,
that's what I wanted .
Tanveer
[ August 20, 2004: Message edited by: Tanveer Rameez ]
 
GeeCON Prague 2014
 
subject: Changing options(contents) of a select element in Struts' jsp form