[英]validating input fields with javascript onsubmit
<input style="position:relative;" type="text" name="posted_settings[pprice]" value="" />
<script type="text/javascript">
function CheckOrderForm(frm){
if(frm.elements["pprice"]'.value==""){
alert("Please enter price");
frm.elements["pprice"].focus();
return false;
}
return true;
}
</script>
Code above only work when name="pprice". 上面的代码仅在name =“ pprice”时有效。 How to make the code to work to perform the check on posted_settings[pprice]?
如何使代码起作用以对posted_settings [pprice]执行检查?
frm.elements["posted_settings\[pprice\]"]
frm.elements["posted_settings[pprice]"].value;
JS Fiddle: http://jsfiddle.net/wTC6X/ JS小提琴: http : //jsfiddle.net/wTC6X/
BTW: There is syntax error in the posted code: 顺便说一句:在发布的代码中有语法错误:
frm.elements["pprice"]'.value==""
The '
after the last closing bracket creates and unterminated String literal. 最后一个方括号后的
'
将创建不终止的String文字。
Let me guess ... u wann't check the input of a form which contains several input field . 让我猜测...您不会检查包含多个输入字段的表单的输入。
from the code u wrote , did u meant to having a array of inputs ? 从您编写的代码来看,您是否要拥有一系列输入? when u do , just do as below :
当您这样做时,请执行以下操作:
<input style="position:relative;" type="text" name="posted_settings[]" value="" />
<input style="position:relative;" type="text" name="posted_settings[]" value="" />
<input style="position:relative;" type="text" name="posted_settings[]" value="" />
here are an array of input fields . 这是输入字段的数组。 let do the form check for them :
让我们为他们检查表格:
here is the example code : [link] http://jsbin.com/uhizoRA/90/edit 这是示例代码:[link] http://jsbin.com/uhizoRA/90/edit
wish u good luck ! 祝你好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.