Jquery Getting Values From Multiple Selects Together
Solution 1:
You are only selecting the initial value. You need to get the value inside the change event.
$("select").change(function () {
var value = $(this).val()
alert(value);
})
Solution 2:
You set your value before the change try this:
<script>
$("select").change(function () {
var value = $(this).val()
alert(value);
})
</script>
Solution 3:
Calling var value = $("select").val()
will save the value of the first <select>
element matched by the selector into a variable as it was when that code was run - it won't update when you change the value of that element.
Instead, what you can do is use this
inside your change()
callback function to refer to the <select>
element that has changed, and get its value, like this:
$("select").change(function () {
alert(this.value);
});
Solution 4:
You would do something like this:
$("select").change(function () {
alert($(this).val());
})
You are only getting the value out once and then just displaying the same thing on the change event.
See working demo : http://jsfiddle.net/JsKeS/
Solution 5:
First of all wrap your script in $(document).ready()
, so that it will be executed after the page loaded. Secondly get the value of select inside the callback:
$(document).ready(function(){
var value = $("select").val()
$("select").change(function () {
alert($(this).val());
});
})
Post a Comment for "Jquery Getting Values From Multiple Selects Together"