现在这是另一个问题.. 我的代码:
<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>
现在调用验证并且还显示警告框,但表单仍在提交中。错误在哪里?
答案 0 :(得分:4)
您在此处手动调用submit()
:
onclick="this.form.submit();"
只需删除onclick
处理程序,就不需要该处理程序,它会自动发生,因为它位于<form>
内。
以下是比较:your current code, with onclick
(仍在提交)与your code with onclick
removed(仅在有效时提交)。
答案 1 :(得分:1)
从input-submit标记中删除onclick="this.form.submit();
。
答案 2 :(得分:1)
尝试使用类型为submit
且无onclick
事件
<input type="submit" id="submit"/>
你可以把图像放在css中
input#submit {
background-image: images/submit.gif;
width: 60px;
}