jQuery get value of select onChange

0 votes

I was under the impression that I could get the value of a select input by using this:- $(this).val();

and applying the onchange parameter to the select field.

It would appear it only works if I reference the ID. How could I do this using this? 

Feb 11 in Java by Rahul
• 8,980 points
42 views

1 answer to this question.

0 votes

Try the following lines of code-

$('select').on('change', function() { 
    alert( this.value ); 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
</script> <select> 
            <option value="1">One</option> 
          <option value="2">Two</option> 
</select>

You can also reference with onchange event-

function getval(sel) 
{ 
      alert(sel.value); 
}
<select onchange="getval(this);"> 
      <option value="1">One</option> 
      <option value="2">Two</option> 
</select>

answered Feb 11 by Soham
• 8,730 points

Related Questions In Java

0 votes
2 answers

How can I get the filenames of all files in a folder which may or may not contain duplicates

List<String> results = new ArrayList<String>(); File[] files = ...READ MORE

answered Sep 12, 2018 in Java by Sushmita
• 6,900 points
1,043 views
0 votes
2 answers

Get all the permutations of a string in Java

You could use recursion to do this.  Try ...READ MORE

answered Aug 21, 2019 in Java by Sirajul
• 59,170 points
799 views
0 votes
1 answer

How to get the number of digits in an int?

You can find out the length of ...READ MORE

answered May 14, 2018 in Java by Akrati
• 3,170 points
398 views
0 votes
1 answer

get a class instance of generics type T

The short answer is, that there is ...READ MORE

answered May 29, 2018 in Java by Parth
• 4,630 points
586 views
0 votes
1 answer

How to use jquery with asp.net ajax?

If you weren't aware, Microsoft is planning ...READ MORE

answered Oct 15, 2018 in IoT (Internet of Things) by Annie97
• 2,160 points
162 views
0 votes
1 answer

Is 'sparkline' a method?

I suggest you to check 2 things That jquery.sparkline.js is actually ...READ MORE

answered Nov 9, 2018 in Apache Spark by Frankie
• 9,830 points
551 views
0 votes
1 answer

What is the syntax of SELECT statement?

This statement is used to select data ...READ MORE

answered Nov 27, 2018 in Database by Sahiti
• 6,360 points
327 views
0 votes
1 answer

What is jQuery?

Hey, jQuery is a fast and concise JavaScript ...READ MORE

answered Feb 14, 2020 in JQuery by kartik
• 37,510 points
283 views
0 votes
1 answer

jQuery AJAX submit form

There is a simple input mentioned below ...READ MORE

answered Feb 8 in Java by Soham
• 8,730 points
76 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP