0

I am using following script but the problem is script is not working properly.Some time work and some time show wrong text.Instead of selected text.it Show me full text like this.

SELECT MINOR علوم الحاسب الآلي هندسة الطيران والفضاء والتكنولوجيا

<select class="cslMinor_Title" id="slMinor_Title">
    <option value="-1">Select Minor</option>
    <option value="201">علوم الحاسب الآلي</option>
    <option value="203">نظم المعلومات</option>
    <option value="299">تكنولوجيا المعلومات الأخرى</option>
</select>


 $('#slMinor_Title').on('change', function () 
 {
     alert($('.cslMinor_Title').find('option:selected').text());
 });

This is happen when i submit FORM through update panel and i am using this option in dialog box. I want selected text not like below

SELECT MINOR علوم الحاسب الآلي هندسة الطيران والفضاء والتكنولوجيا and also i tried many options like below

jQuery("#slMinor_Title option:selected").text()

But all are giving same result.Guide me what is the problem with code.

x2.
  • 9,554
  • 6
  • 41
  • 62
test twes
  • 251
  • 1
  • 2
  • 5
  • 1
    Try changing your `` to ``. As I guess that might be the issue – Nad Apr 27 '15 at 05:34
  • I replaced with 0 but nothing happen – test twes Apr 27 '15 at 05:38
  • It seems to work fine. What do you mean this happens when you submit the form? –  Apr 27 '15 at 05:46
  • when i submit form it shows me full text like SELECT MINOR علوم الحاسب الآلي هندسة الطيران والفضاء والتكنولوجيا instead of selected option value text – test twes Apr 27 '15 at 05:58
  • Dude it works fine I tried it on fiddle http://jsfiddle.net/cbobtp8t/ may be if it is browser issue post what type of browser u are using and try it on fiddle urself too – dsharew Apr 27 '15 at 06:05
  • @testtwes, please make a jsFiddle for us, as the same code is working for others – Puneet Apr 27 '15 at 06:39
  • I am using firefox and asp.net c# as backend.So its impossible for me to create js fiddle. – test twes Apr 27 '15 at 06:47
  • @testtwes: I think you should check your code again, as suggested by `codehx` its working fine. – Nad Apr 27 '15 at 07:32

2 Answers2

0

Try val() function to get value.

jQuery("#slMinor_Title option:selected").val();

Mark it as answer if you think it is helpful for you.

JSP.NET
  • 188
  • 13
0

See this

$('#dropDownId :selected').text();
Community
  • 1
  • 1
JSP.NET
  • 188
  • 13