尝试在输入文本后自动提交表单 [英] trying to auto submit form after text input

查看:61
本文介绍了尝试在输入文本后自动提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是表单应如何执行:

Here is how the form is supposed to execute:

   <script>
    $(document).ready(function(){

    $("#submit").click(function(){

        //access token stuff
        var token = $("#link_input").val(); ... etc</script>

.

一旦超过10个字符,我将尝试自动提交此信息.通常,您在输入字段中填写文本区域,然后单击提交.单击提交按钮后,JS会验证输入框中的文本,如果有效,它将执行.如何在不单击提交按钮的情况下自动提交输入框中的文本?

I am trying to auto submit this info once it exceeds 10 characters. Normally you fill out the text area in the input field and you click submit. Upon clicking the submit button the JS validates the text in the input box and if it's valid it executes. How can I auto-submit the text in the input box without having to click the submit button?

<script language="JavaScript" type="text/JavaScript"> 
var x=10;//nr characters 
function submitT(t,f){ 
if(t.value.length==x){ 
f.submit() 
} 
} 
</script> 


                    <input id="link_input" onkeyup="submitT(this,this.form)" autofocus="true" autocomplete="off" placeholder="http://www.facebook.com/connect/login_success.html#access_token=AAAZDCiOS6Ls0BAMUKJDvLZCTgZDZD" style="width: 600px;margin-left: -11%;" value="" name="url">

                    <br/>



<div id="Wait" style="display:none;"><center>Processing your form<br><img src="http://i.imgur.com/kKqSe.gif"></center></div>

                    <br/>


                    <center>
                    <a href="javascript:void(0)" id="submit" onkeyup="submitT(this,this.form)" autofocus="true"><img src="http://i.imgur.com/eA6fv.png" style="border:0px;padding-top:5px;"></a>

推荐答案

只需测试与您已有的类似的keyup.

Just test against keyup similar to what you have already.

<form action='someplace' id='myform' method='post'>
  <input type='text' id='link_input' ...other stuff />
</form>

jquery:

$('#link_input').on('keyup',function(){
  var val = $(this).val();
  var len = val.length;

  if(len == 10){
    $('#myform').submit();
  }
});

这篇关于尝试在输入文本后自动提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆