如何使用textbox onchange值自动提交表单?

时间:2018-05-29 11:26:46

标签: javascript php html

+---------------------+----------------------------------------+------------------------------------------+-------+
|      timestamp      |              productHash               |               applierHash                | asset |
+---------------------+----------------------------------------+------------------------------------------+-------+
| 2014-12-30 23:37:32 | cHJvZF81YWZhZmJkY2JiMzQ0OC4yMTg5MTY3OQ | bWF0QXBwXzVhZmFmYmRjY2E1ZTExLjE3NDA3NjYx | val1  |
| 2014-12-30 23:37:32 | cHJvZF81YWZhZmJkY2JiMzQ0OC4yMTg5MTY3OQ | bWF0QXBwXzVhZmFmYmRjY2Q1MmE0LjI3NTA4Nzcx | val2  |
| 2014-11-30 19:17:47 | cHJvZF81YWZiZDVlOTQ3ZjM5Mi44NTc2Mjc0MQ | bWF0QXBwXzVhZmJkNWU5NDdmNWQ0LjU1MzQ1NDg5 | val3  |
| 2014-11-30 19:17:47 | cHJvZF81YWZiZDVlOTQ3ZjM5Mi44NTc2Mjc0MQ | bWF0QXBwXzVhZmJkNWU5NmY2MTA0LjQyOTkxNzY5 | val4  |
| 2014-11-30 19:17:47 | cHJvZF81YWZiZDVlOTQ3ZjM5Mi44NTc2Mjc0MQ | bWF0QXBwXzVhZmJkNWU5OTZlNGU3LjcxNTI1MDY1 | val5  |
+---------------------+----------------------------------------+------------------------------------------+-------+

这是我整个系统的一部分,我问如何在没有按下提交按钮或输入按钮的情况下更改文本框值时如何自动提交表单谢谢

2 个答案:

答案 0 :(得分:0)

HTML

<select id="id" class="drpdwn" value=" " onchange='getCity()'>

脚本

function getCity(){

    var state=$('#id').val();// it should contain some value

    $.ajax({
        url: "<?php echo base_url() ?>getCity/"+state, //your url and values
        dataType: "json",
        success: function(result){               
           $.each( result, function( key, value ) {                  
          //what you want to do after posting?
            });  
    }});

 }

答案 1 :(得分:0)

您不需要任何函数来触发选择值的onchange()。您可以使用this.form.submit()函数中的onchange()更改选择值时提交表单,如下所示。

<select id="periodname" class="drpdwn" value=" " onchange='this.form.submit()'>

&#13;
&#13;
$("#textF").keyup(function() {
    console.log($("#textF").val());
    $('#form2').delay(200).submit();
});

$("#textF2").change(function() {
    console.log($("#textF2").val());
    $('#form2').delay(200).submit();
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="path1">
    <select id="periodname" class="drpdwn" value=" " onchange='this.form.submit()'>
        <option>test1 </option>
        <option>test2 </option>
        <option>test3 </option>
    </select>
</form>




<form action="path2" id="form2">
    <input type="text" id="textF" placeholder="onkeyup()">
    <input type="text" id="textF2" placeholder="onchange()">
</form>
&#13;
&#13;
&#13;