views:

55

answers:

3

I want to get the value to of drop down list, to send back to server to match something.

Update:

Sorry, i has to be clear on my question. I am using javascript to get values in client side and sending those back to server with DWR & processing them with JAVA code.

<select><option selected="selected" value="1">EEE</option><option value="2">ECE</option><option value="3">IT</option><option value="4">CSE</option><option value="5">MECH</option></select>

'

<input id="id" type="text" size="5"/>
<input id="name" type="text" size="15"/>
<input id="age" type="text" size="5"/>
<input id="age" type="text" size="5"/>

'

I want to get the values(1,2,3,4,5) ALONG with the other Name, Id, Age values. I can get field text using dwr.util.getValues().

How can I get that select option value?

+1  A: 

Since you specify no server-side language, I assume you want in HTML/JS. So, use this code in javascript, assuming the ID of your combobox is combo1:

<script type="text/javascript">
   var combo1 = document.getElementById("combo1");
   var val = combo1.options[combo1.selectedIndex].text;

   //this will show the value in a Dialog Box
   alert(val);
</script>
shamittomar
He does say "to send back to server to match something" so maybe he means AJAX. Either way, confusing question.
alex
Yes, if he can code in `AJAX`, I just told him how to get the value. Rest depends on him, how to send this by `AJAX`.
shamittomar
@Alex: Sorry, alex... the question is updated now.
NooBDevelopeR
@shamittomar: yea... You are right!!!
NooBDevelopeR
A: 

Try giving your select element a name attribute:

<select name='department'>...
yfrangi
A: 
<select id="id"> ...

var opts = dwr.util.byId("id").options; 
Torres
var employee = { id:null, name:null, age:null};dwr.util.getValues(employee);var opts = dwr.util.byId("id").options;employee = employee.add(opts);will it work?
NooBDevelopeR
http://directwebremoting.org/dwr/browser/util/addOptions.html
Torres