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?

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

本文标签:

Error[2]: Invalid argument supplied for foreach(), File: /www/wwwroot/roclinux.cn/tmp/view_template_quzhiwa_htm_read.htm, Line: 58
File: /www/wwwroot/roclinux.cn/tmp/route_read.php, Line: 205, include(/www/wwwroot/roclinux.cn/tmp/view_template_quzhiwa_htm_read.htm)
File: /www/wwwroot/roclinux.cn/tmp/index.inc.php, Line: 129, include(/www/wwwroot/roclinux.cn/tmp/route_read.php)
File: /www/wwwroot/roclinux.cn/index.php, Line: 29, include(/www/wwwroot/roclinux.cn/tmp/index.inc.php)