开发者

How to check input text into web form? java script

how to check input text before POST operation? it must be numbers only

<form method="post" action="credit.php">
Сумма кредита: <input type="text" name="sum"> <br />
первый взнос: <input type="text" name="pv"> <br />
Срок: <input type="text" name="srok"> <br />
Процентная ставка: <inp开发者_如何学Cut type="text" name="percent"> <br />
<input type="submit">
</form>

sorry for my bad english.


Use some kind of javascript..

<form method="post" action="credit.php" onsubmit="validateForm()">
<input type="text" name="pv" id="pv"> <br />
....
</form>


<script type="text/javascript">
function validateForm() {
  var result =  /^\d+$/.test(document.getElementById('pv').value);
  return result

}
</script>

If your onsubmit returns false, the form won't go. If it returns true, the form will submit.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜