admin管理员组

文章数量:1331849

<script type="text/javascript" src="//ajax.googleapis/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $("#btn").click(function() {
        var val = "Hi";
        $.ajax ({
            url: "1.php?id",
            data: { id : val }

        });
    });
});
</script>

<form name="numbers" id="numbers">
    <input type="text" name="id" id="btn">
<input type="text">
</form>

This code is for click event but i want onchange event like on select option. Can anybody suggest me how to add onchange event on this ajax code? Thank you in advance.

<script type="text/javascript" src="//ajax.googleapis./ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $("#btn").click(function() {
        var val = "Hi";
        $.ajax ({
            url: "1.php?id",
            data: { id : val }

        });
    });
});
</script>

<form name="numbers" id="numbers">
    <input type="text" name="id" id="btn">
<input type="text">
</form>

This code is for click event but i want onchange event like on select option. Can anybody suggest me how to add onchange event on this ajax code? Thank you in advance.

Share Improve this question edited Feb 2, 2015 at 12:02 donald123 5,7593 gold badges28 silver badges24 bronze badges asked Feb 2, 2015 at 12:02 learnerlearner 211 gold badge1 silver badge4 bronze badges 2
  • Search here: api.jquery./category/events – yunzen Commented Feb 2, 2015 at 12:03
  • Where is select and option? – Manwal Commented Feb 2, 2015 at 12:03
Add a ment  | 

3 Answers 3

Reset to default 2
$(document).ready(function(){
    $("#btn").on("change", function() {
        var val = "Hi";
        $.ajax ({
            url: "1.php?id",
            data: { id : val }

        });
    });
});
<input type="text" name="id" id="btn" onchange="ajaxfunction()" />

<script>
function ajaxfunction()
{
    enter ajax code here
}
</script>

You can try using keyup like so.

$(document).ready(function () {
    $("#btn").keyup(function () {
        var val = $(this).val();
        $.ajax({
            url: "1.php?id",
            data: { id: val }

        });
    });
});

本文标签: javascriptHow to add onchange event on ajaxStack Overflow