检查输入值长度 [英] Check input value length
本文介绍了检查输入值长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在输入检查方面遇到问题.如果输入长度小于 3,我不想发送请求.
I have a problem with input checking. I don't want to send the request if the input length is less than 3.
我的表格:
<form method='post' action=''>
Albūma nosaukums: # # this is the input --><input id='titleeee' type='text' name'album_title' /><br />
Bilde Nr 1: <input type='file' name='pic_nr1' /><br />
Bilde Nr 2: <input type='file' name='pic_nr2' /><br />
Bilde Nr 3: <input type='file' name='pic_nr2' /><br />
Aktīvs*:
<select>
<option>Jā</option>
<option>Nē</option>
</select>
<br />
<input Onclick='testlenght(document.getElementById("titleeee"), "Tavs albūma nosaukums ir pa īsu!", "3")' type='submit' value='Pievienot' />
</form>
推荐答案
您可以添加一个表单 onsubmit 处理程序,例如:
You can add a form onsubmit handler, something like:
<form onsubmit="return validate();">
</form>
<script>function validate() {
// check if input is bigger than 3
var value = document.getElementById('titleeee').value;
if (value.length < 3) {
return false; // keep form from submitting
}
// else form is good let it submit, of course you will
// probably want to alert the user WHAT went wrong.
return true;
}</script>
这篇关于检查输入值长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文