...

View Full Version : Get value of selected option in a multiple select box



maxpouliot
04-25-2007, 08:23 PM
Hi,

i have a multiple select box


<select onchange='getvalue(this)' class=textField multiple size="5" id="fenetre" name="fenetre">

and a function :
[CODE]function getvalue(nom)
{
var selectedValue=nom.value;
alert(selectedValue);
}CODE]

my problem is the following :

when i click on an option in the select box, the alert always shows me the first option that is selected. For example, if i click the third option and the first option is already selected, the alert shows the value of the first option when i want to know which option the user has just clicked.

Thanks

never-online
04-25-2007, 09:05 PM
<select onchange='getvalue(this)' class=textField multiple size="5" id="fenetre" name="fenetre">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<script type="text/javascript">
//<![CDATA[
function getvalue(nom)
{
var a=nom; var result=[];
for (var i=0; i<a.length; i++) {
a[i].selected?result.push(a[i].value):"";
}
result?new function(){
alert("the result is: " +result);
alert("now you select the value is: " +result.reverse().slice(0,1));
}:"";

}
//]]>
</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum