Get Seleceted Dropdown Option Value Jquery
I have two dropdowns -- for the month and year -- and a button. When the user clicks the button, I want to grab the selected month value and year value and pass them as query strin
Solution 1:
There is a mistake in T. Stone's answer. the selector should have a dot. Other than that - great answer!
<script>
$(function(){$(".btnBlue").click(function(){
window.location = "https://mysite.com/events.aspx?my=" + $(".inpMonth select").val().toLowerCase() + $(".inpYear select").val();
})})
</script>
Solution 2:
I'm assuming you want this all to happen on the click event of btnBlue
.
Start with a click handler...
$('a.btnBlue').click(function() {
// ...
});
Then get the values of the month/year...
var month = $('.inpMonth select').val();
var year = $('.inpYear select').val();
Then navigate to that URL...
window.location.href = 'https://mysite.com/events.aspx?my=' + month + year;
All together that's...
$('a.btnBlue').click(function() {
var month = $('.inpMonth select').val();
var year = $('.inpYear select').val();
window.location.href = 'https://mysite.com/events.aspx?my=' + month + year;
});
Solution 3:
first, get references to your SELECT and LINK dom objects:
var button = $('a.btnBlue');
var month = $('#datepicker .inpMonth select');
var year = $('#datepicker .inpYear select');
next, create a function to return the current month & year as a string:
function currentSelection() {
return month.val() + year.val();
}
create a function which navigates you to the new url based on currentSelection():
function navigateToDate() {
window.location.href = "https://mysite.com/events.aspx?my=" + currentSelection();
}
when the button is clicked, call navigateToDate():
button.click( navigateToDate );
Solution 4:
To get the month try
$(".inpMonth select").val();
To parse a whole form give .serialize() and .serializeArray() a try
$("form").serialize()
Post a Comment for "Get Seleceted Dropdown Option Value Jquery"