开发者

Use option value as a filename variable in a jquery function

how can I pass the option value to the filename below? My purpose is to create files e.g. 1.php 2.php 3.php .... but I dont know how to pass it as a variable. Thanks.

    <form>
        <select id="termid">
            <option value="">- select -</option>
            <option value="1">Option 1</option>
            <option value="2">Option 2</option>
            <option value="3">Option 3</option>
            <option value="4">Option 4</option>
<option value="other">Other</option>
        </select>  
   开发者_如何学Python </form>


Is this what you meant?

$('#termid').change(function() {
    var val = $(this).val();
    $('#some_div_below_select').load(val + '.php',
    {
        value: val
    });
});


$('#termid option:selected').val() instead of THE OPTION VALUE should work.

Here's a jsfiddle to demonstrate getting the value.


You can use jQuery val() to get the value of the selected option when you handle the change event, and you can then use that to build up the string for your URL, like this:

$(document).ready(function() {
  $('#termid').change(function() {
    var selectedVal = $(this).val();
    $('#some_div_below_select').load(selectedVal  + '.php', { "value" : selectedVal });
  });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜