admin 管理员组文章数量: 1086019
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());
}
本文标签:
版权声明:本文标题:javascript - How do I detect in jQuery (AJAX) when a drop down item is selected on my HTMLPHP page? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744062225a2526931.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论