It's easier than you think. Just use the value of the select element itself:


function specify( select ){
    var spName = select.value;
    alert( spName );
}

You may want to run the same code on the keyup event as well as the change
event, to make the cursor keys select immediately:

<select onchange="specify(this)" onkeyup="specify(this)" ...>

And, of course, you can use jQuery event handling instead of the inline
event handling if you wish:

<select id="specifier">
...

$('#specifier').change( specify ).keyup( specify );

function specify(){
    var spName = this.value;
    alert( spName );
}

-Mike

> -----Original Message-----
> From: [email protected] 
> [mailto:[EMAIL PROTECTED] On Behalf Of andyGr
> Sent: Sunday, June 01, 2008 9:35 PM
> To: [email protected]
> Subject: [jQuery] Select option value
> 
> 
> 
> Hi All,
> 
> Here is a simple code:
> 
> <select onchange="specify(this)" ...>
> <option....>.....</option>
> <option....>.....</option>
> ......
> <option....>.....</option>
> </select>
> 
> How can I get the value of the selected option? I tried
> 
>  function specify(current){
>        var spName = $j(current+" option:selected").val();
>        alert(spName);
>        
>  }
> 
> But it returns undefined value. What is wrong here?
> 
> Thanks
> --
> View this message in context: 
> http://www.nabble.com/Select-option-value-tp17592925s27240p175
> 92925.html
> Sent from the jQuery General Discussion mailing list archive 
> at Nabble.com.
> 

Reply via email to