![](/img/trans.png)
[英]Javascript validation: Return false not working, form still submitting
[英]validation not working still submitting the form
现在这是另一个问题..我的代码:
<script type="text/javascript">
function validate_form ()
{
if ( document.myform.tele_caller.value == "" )
{
alert ( "Please insert the Name" );
return false;
}
else
{
return true;
}
}
</script>
和表格-
<form action="telecallerinfo.php?action=modify&id=<?php echo $id;?>" method="post" enctype="multipart/form-data" name="myform"
onsubmit="return validate_form ( );">
<table class="panel1">
<tr>
<td align="center">Caller Name:
<input name="tele_caller" type="text" size="15" value="<?php echo $tele_caller?>" /></td>
</tr>
<tr>
<td align="right">
<input name="submit" id="submit" type="image" src="images/submit.gif" width="60" onclick="this.form.submit();"/>
<a href="telecallerinfo.php"><img src="images/cancel.gif" height="25" width="70"/></a>
</td>
</tr>
</table>
</form>
现在将调用验证,并且还会显示警告框,但仍在提交表单。 错误在哪里?
您正在此处手动调用submit()
:
onclick="this.form.submit();"
只需删除该onclick
处理程序,就不需要该处理程序,因为它位于<form>
内部,它将自动发生。
比较如下: 您当前的代码,其中onclick
(仍在提交)与您的代码中的onclick
被删除 (仅在有效时提交)。
从输入提交标签中删除onclick="this.form.submit();
尝试使用类型为submit
且没有onclick
事件的输入
<input type="submit" id="submit"/>
你可以将图像放在css中
input#submit {
background-image: images/submit.gif;
width: 60px;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.