*
The moose likes Struts and the fly likes Drop down values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Drop down values " Watch "Drop down values " New topic
Author

Drop down values

Ananth Ram
Ranch Hand

Joined: Jan 18, 2001
Posts: 99
Hi all,

I am using a drop down with three selections.

<select name="type" onchange="choose(this.options[this.selectedIndex].value)">
<OPTION VALUE="RC">O1</OPTION>
<OPTION VALUE="RS">O2</OPTION>
<OPTION VALUE="RP" >O3</OPTION>
</select>

I want to get the selected values from the drop down before submitting the form.

Any help,

Thanks in advance,

Ananth
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61043
    
  66

Originally posted by Ananth Ram:
I want to get the selected values from the drop down before submitting the form.
Get it where? In JavaScript? it appears that you already know how to do that in your event handler.

On the server? Why would you need it prior to form submission? The answer to that question may have a great effect on the answer.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ananth Ram
Ranch Hand

Joined: Jan 18, 2001
Posts: 99
Thanks.

I awant to pick up the value and pass it to servlet, once the form is submitted, but the drop down is not part of the Action form ( I am using Struts). Could you please help me.

Ananth
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
If the control is inside of the form tag then the name/value pair will post to the servlet and you can get it from the request
Ananth Ram
Ranch Hand

Joined: Jan 18, 2001
Posts: 99
Thanks,

I am not able to get the picture. Could you help me explain more..

Ananth
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61043
    
  66

It can't get much clearer; if the select element is in the form it will be submitted to the server.

Is it in the form?

Is it getting the value on the server that's what's really giving you an issue?
Ananth Ram
Ranch Hand

Joined: Jan 18, 2001
Posts: 99
Thanks in advance.

The problem is that I want to hold the dropdown selected value in a variable and pass it on to database based on the selection, dropdown is inside a form. The form data is pertaining to one table and the drop down values are to a different table. Is there anyway I can get hold of the values and pass it on to database. The form


function enableSelected() {
document.messagesForm.selectedEmails.disabled = false;
}

<html:form action="actionProcess.do?method=addValue" method="post" onsubmit="enableSelected();">

<select name="type" >
<OPTION VALUE="RC">O1</OPTION>
<OPTION VALUE="RS">O2</OPTION>
</select>

Thanks,
Karthik
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
submit the form in your method. Then follow our earlier directions.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61043
    
  66

This is all something that you need to do on the server side. Since you are using Struts, I've moveed this to the appropriate forum.
Ananth Ram
Ranch Hand

Joined: Jan 18, 2001
Posts: 99
Thanks.

I resolved the issue, by adding the drop down as property in form. It also helps me to validate the drop down.

Thanks for the help.

Ananth
 
Don't get me started about those stupid light bulbs.
 
subject: Drop down values