How do I detect in jQuery (AJAX) when a drop down item is selected on my HTML page so I can refresh the page? Here is the code for my drop down:
<select id="dropdown">
<option value="test1">test1</option>
<option value="test2">test2</option>
</select>
And here is code I have been using to detect a click... how can I get it to detect a change in my drop down?
<script type="text/javascript" src=".5.1/jquery.min.js"></script>
<script type="text/javascript">
// This is our actual script
$(document).ready(function(){
$('#dropdown').click(function(){
$.ajax({
location.reload();
});
return false;
});
});
</script>
And also, bonus question, right before location.reload();
how can I set a $_SESSION
variable in PHP of the select drop down value?
How do I detect in jQuery (AJAX) when a drop down item is selected on my HTML page so I can refresh the page? Here is the code for my drop down:
<select id="dropdown">
<option value="test1">test1</option>
<option value="test2">test2</option>
</select>
And here is code I have been using to detect a click... how can I get it to detect a change in my drop down?
<script type="text/javascript" src="http://ajax.googleapis./ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
// This is our actual script
$(document).ready(function(){
$('#dropdown').click(function(){
$.ajax({
location.reload();
});
return false;
});
});
</script>
And also, bonus question, right before location.reload();
how can I set a $_SESSION
variable in PHP of the select drop down value?
4 Answers
Reset to default 4When the select is changed, reload the page with a querystring with the selected value
$(document).ready(function(){
$('#dropdown').on('change', function() {
window.location.href = window.location.href + '?value=' + this.value;
});
});
it's a simplified example. you'll probably need some parsing for changing the querystring multiple times.
Then catch in PHP and set the $_SESSION etc.
$_SESSION['value'] = $_GET['value']
You can use a $(selector).change()
in staed of $(selector).click()
$('#dropdown').change(function(){
//your code goes here
});
Think you're looking for .change()
(Documentation)
with .change
$("#elementID").change(function() {
alert($("#elementID").val());
}