I am having a table inside a form. I want all the three columns details to be entered by the user. if the user leaves anyone of them, it should show an alert message like "Please enter the name, it cannot be blank". if all the fields are filled then only the insert into should come into act.
<table> <!--cellpadding=15 cellspacing=3-->
<tr><td>Name</td><td>: <input type="text" name="name"></td></tr>
<tr><td>Address</td><td>: <input type="text" name="address"></td></tr>
<tr><td>Phone No</td><td>: <input type="text" name="dept_id"></td></tr>
</table>
Try to use a flag variable.
<input type="text" name="name" id="nameId">
<input type="text" name="address" id="addressId">
<input type="text" name="dept_id" id="dept_id">
Call this method in onSubmit()
function validate()
{
var validate = false;
if(document.getElementById("nameId").value == "")
{
alert("NAME IS REQUIRED");
validate = true;
}
...................
...................
return validate ;
}