To answer your question as far as what is _wrong_ with your code -
AFAIK, you can't mix an object reference (variable) & a text string
within a single jQuery selector parameter. You have the right idea
though. Modifying what you had just a little will work:

      var spName = $("option:selected",current).val();

.. which matches "option:selected" within the context of your
"current" object reference. Using that second selector parameter is a
good idea whenever you have a "this" object reference available where
you're selecting children of that object... it cuts down the amount of
work jQuery has to do.

What Michael Geary suggested definitely works fine with all modern
browsers. A lot of developers I know still prefer to use the old-
school method of getting the value of the selected option though, for
no very good reason anymore except habit.

-Wick
CarComplaints.com


On Jun 2, 12:35 am, andyGr <[EMAIL PROTECTED]> wrote:
> 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-tp17592925s27240p17592925.html
> Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Reply via email to