I think, I got a validation problem on my javascript. It still submits while the form is invalid. Specifically, when user inputs more than 10 character in length, it still submits the form into database, while it should display alert. Here's the script:
<script type="text/javascript">
function validateForm()
{
var numericExpression = /^[0-9]+$/;
var a=document.forms["purchaseform"]["no"].value;
var b=document.forms["purchaseform"]["qty"].value;
if (a==null || a=="")
{
alert("Form number must be filled out");
return false;
}
if(a.match(numericExpression))
{
return true;
}
else
{
alert("Form number must be filled with numbers only");
return false;
}
if(a.length > 10) //i got a problem with this one i think
{
alert("Form number must not be greater than 10 character length");
return false;
}
if (b==null || b=="")
{
alert("Quantity must be filled out");
return false;
}
if(b.match(numericExpression))
{
return true;
}
else
{
alert("Quantity must be filled with numbers only");
return false;
}
}
</script>
And here is the form snippet:
<form name="purchaseform" method="post" onsubmit="return validateForm()" action="submitpurchaseadmin.php">
<table>
<tr>
<td>Form number</td>
<td><input type="text" name="no"></td>
</tr>
<tr>
<td>Category</td>
<td>
<select id="cat" name="cat">
</select>
</td>
</tr>
<tr>
<td>Item</td>
<td>
<select id="item" name="item">
</select>
</td>
</tr>
<tr>
<td>Quantity</td>
<td><input type="text" name="qty"></td>
</tr>
<tr>
<td>Date</td>
<td><input type="text" name="date" value="<?php echo date("d-m-Y"); ?>"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit" value="Save"></td>
</tr>
</table>
</form>