I have a form

<select name="city" id="city"> <option value=0>Санкт-Питербург</option> <option value=1>Москва</option> </select> 

To get a value using jQuery, you need to do this $ ('# city'). Val (); It's not a problem. And how can I get the very words of St. Petersburg, or Moscow, instead of the numbers 0 or 1?

Immediately say that you can not change anything in the form, and handle the type

  if(this.value==0){alert('Спб');} else if(this.value==1){alert('Мск')} 

too, because there can be more than 20 elements in the form, you cannot process everything, you need to directly get this label. Tell me how?

    1 answer 1

    Well, since you're talking about jquery then:

     $(":selected",this).text(); 
    • I tried. he brought me all in one line St. Petersburg Moscow And how to do only what was chosen. looking for here is the answer. - chuikoff
    • I found everything))) $('#city option:selected').text(); - chuikoff
    • I corrected - DemoS