-2

任何有助于我在 9 个字符后提交表单的 onkeyup 或 onclick javascript 代码。

我的 HTML 代码。我正在使用 AJAX 获取数据。我尝试了很多脚本。没有一个对我有用:'(

Enter Your Car No : <input type="text" name="car"  maxlength="9" id="carno" value="<?php echo $_REQUEST["carno"]; ?>"/>
4

2 回答 2

0

尝试这个 :

Enter Your Car No : <input type="text" name="car"  maxlength="9" id="carno" value="<?php echo $_REQUEST["carno"]; ?>" onkeypress="submitForm()" onclick="submitForm()"/>
<script>
   function submitForm(){
       var len = document.getElementById("carno").value.length;
       if(len >= 9 ){
           //submit form code
       }else{
           return false;
       }
   }
</script>
于 2013-04-19T05:49:36.040 回答
0
Enter Your Car No : <input type="text" name="car"  maxlength="9" id="carno" onkeypress="yourFunction()" value="<?php echo $_REQUEST["carno"]; ?>"/>

<script>
function yourFunction(){
  var textValue = document.getElementById('carno').value;
  if(textValue.length >= 9){
       //implement your ajax code
  }
}
</script>


Hai here i am calling function on each key press in that text field and i am getting the value using id and checking that length if its >=9 (ur requirement) so write ajax code 
于 2013-04-19T05:39:22.760 回答