最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I detect in jQuery (AJAX) when a drop down item is selected on my HTMLPHP page? - Stack Overflow

programmeradmin1浏览0评论

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?

Share Improve this question asked Dec 4, 2013 at 16:30 Ethan AllenEthan Allen 14.9k25 gold badges114 silver badges205 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 4

When 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());
}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论