Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

select another dropdown based on a selection from first dropdown using <html:select> struts tag

 
raj mal
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the below dropdowns. I need to select the second dropdown (email) when the user select an entry in first dropdown (accounts). if accountid2 is selected, email-id2 must be selected. if other, other should be selected. how to do that using onchange fuction. please note that it uses struts tag - <html:select>

<td>1. Member Account Number<span class="bodyCopy"><font color="#ff0000"> * </font></span>:
<html:select name="DataForm" property="accountNumber" styleClass="formContent"
style="width:80px" >

<option>${reDataForm.accountNumber}</option>

<htmlptions collection="<%= WorkConstants.RENewDropdowns.PACCT %>" property="value" labelProperty="label" styleClass="formContent"/>
</html:select>

<td>3. Member <br>E-mail Address:<br /> <span class="bodyCopy" ></span>
<html:select name="DataForm" property="emailAddress" style = "width:150px" styleClass="formContent">
<option>${reDataForm.emailAddress}</option>
<htmlptions collection="<%= WorkConstants.RENewDropdowns.PEMAIL %>" property="value" labelProperty="label" styleClass="formContent"/>
</html:select>
 
Shankar Tanikella
Ranch Hand
Posts: 329
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create an onchange method for the first select to call a javascript and do your logic there...
There is nothing to do with struts here, just simple js, try it
 
raj mal
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Shankar,
the only concern for me is there is no id/name that I can identify. I tried another jsp using regular <SELECT>. Since it is struts tag <html:select> which doesnt have a name/id to give. See my sample code for <SELECT> which works fine. how do you use the same if i have <html:select> tag with label and value (see my code in my first posting)

<HTML>
<HEAD>
<script language="javascript" type="text/javascript" >
<!-- hide

function selectPartner(x){
if (document.form1.Person.value != "null") {
alert(x);
document.form1.Native.options[x].selected =true

}
}

// end hide -->
</script>
</HEAD>
<body>
<form name="form1">
<select name="Person" onChange="selectPartner(document.form1.Person.options[document.form1.Person.options.selectedIndex].value)">
<option>Choose..</option>
<option value=1>Vegitable</option>
<option value=2>Fruits</option>
</select>

<select name="Native">
<option>Native is..</option>
<option value=0>Okra</option>
<option value=1>Apple</option>
</select>

</form>
</body>
</HTML>

 
Shankar Tanikella
Ranch Hand
Posts: 329
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raj, there should be some relation with the two selects that you are using and you can pass that relation ID to the js and still do that
What i can see from the post is the relation is account number and use that account number on selection set the email..

Did i miss something?

 
raj mal
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Shankar.
I have 5 accounts and 5 emails. one to one relationship (means first account corresponds to first email). Both are seprate dropdowns. Could you please shed some more info how to do this as I'm new to javascript.
 
Joe Ess
Bartender
Posts: 9280
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Struts 2 has a doubleselect tag that does what you want.

 
Shankar Tanikella
Ranch Hand
Posts: 329
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raj, Firstly use code tags, its very easy to read and looks good isnt it?...

Anyways, your select box would be like this

and js something like this



Just saw a reply, i though you were using lower versions of struts, if its struts2 please use the double select (what a mistake)
 
raj mal
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe/Shankar,

how do you use doubleselect ? can you please provide an example, based on my requirement ? appreciate your help !
 
raj mal
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shankar, is that how iterate should code ? - ${iterate <%= WorkConstants.RENewDropdowns.PEMAIL %>}
 
Joe Ess
Bartender
Posts: 9280
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you look at the examples on the page I linked? Are you using Struts 2?
 
raj mal
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe, Looks like I'm using older version - Manifest-Version: 1.0. does that mean, I can not use doubleselect ?
if so, could you please let me know how to iterate thru the the list i have (list stored in a constant).
 
Joe Ess
Bartender
Posts: 9280
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
raj mal wrote:Manifest-Version: 1.0.


That refers to the version of the manifest file format, not the Struts version.
Shankar was just giving you the rough outline of the code. We ask that you ShowSomeEffort and try to solve your own problem.
 
raj mal
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Joe. I was trying to iterate using for loop in javascript. But I dont know how to get the values from the session constant - WorkConstants.RENewDropdowns.PACCT . Any help on this would appreciated !
 
Shankar Tanikella
Ranch Hand
Posts: 329
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Set the list in your form to get the same in js or use AJAX to get the list from session asynchronously.

Better try it yourself first and see if you could achieve it. If yes, you would remember it for long else you can put here what you have tried and we shall see whats happening, then again you would remember it for long.
 
raj mal
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks shankar. please look at this code.

function selectEmail(currentAccountNumber){

alert (currentAccountNumber);

for
( int i = 1; i < 6; i++)

{
if (currentAccountNumber = WorkConstants.RENewDropdowns.PACCT.getAccountId1(i) ){
//how to set email here ?

}
}
 
Shankar Tanikella
Ranch Hand
Posts: 329
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try something like this in JS, and again it is just an idea

 
raj mal
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got it . thanks ! appreciate your help !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic