【发布时间】:2017-11-08 06:16:13
【问题描述】:
我遇到了一些与onsubmit return false does not work, form still submits? 非常相似的问题 我已经按照解决方案进行了,但是如果我将其更改为onclick,它将无法正常工作,甚至没有消息提示。
我正在使用的脚本。
<script>
function validate()
{
var validate = false;
if(document.getElementById("nameId").value == "")
{
alert("NAME IS REQUIRED");
validate = false
}
return true ;
}
</script>
我的代码附在下面。
<table class="<?php echo $table_style_3;?>" style='width: auto;'>
<form action="fhd_add_type.php" method="post" class="form-horizontal" onsubmit="return validate()"> //This is the part where i've changed to onclick
<input type='hidden' name='nacl' value='<?php echo $nacl;?>'>
<input type='hidden' name='type' value='<?php echo $type;?>'>
<?php
if ($type <> 0) { ?>
<tr><td>Name: </td><td><input type='text' name='type_name' id = "nameId"></td></tr> //This is the field where need to be validate
<tr><td colspan='2'><input type='submit' value='add' class='btn btn-primary'></td></tr>
</table>
<?php }
if ($type == 0) { ?>
<tr><td>Name</td><td><input type='text' name='type_name' id = "nameId"></td></tr> //This is the field where need to be validate
<tr><td>Email</td><td><input type='text' name='type_email'></td></tr>
<tr><td>Location</td><td><input type='text' name='type_location'></td></tr>
<tr><td>Phone</td><td><input type='text' name='type_phone'></td></tr>
<tr><td colspan='2'><input type='submit' value='add' class='btn btn-primary'></td></tr>
</table>
<?php }?>
</form>
</table>
【问题讨论】:
标签: javascript php jquery validation