HTML/Javascript

SES by business degree online promotion team.

Philippine Airlines International Flight schedules

Philippine Airlines International Flight schedules
Philippine Airlines International Flight schedules

Search This Blog

Wednesday, September 8, 2010

Basic Validation form Data Entry

Before you will decide to save data from html form to MySql database. Much better if you will put first a validation control.

Here is a sample Javascript code for validation.
Note: You can combine javascript validation and php code on saving data.

code to paste:
form_entry.html
<html>
<head>
<script language="javascript">
function validateform()
{
formObj = document.personalinfo;
if (formObj.studentno.value=="")
{
alert("Fill for Student Number");
formObj.studentno.focus();
return false;
}

else if (formObj.lastname.value=="")
{
alert("Fill for Lastname");
formObj.lastname.focus();
return false;
}

else if (formObj.firstname.value=="")
{
alert("Fill for Firstname");
formObj.firstname.focus();
return false;
}

else if (formObj.address.value=="")
{
alert("Fill for Address");
formObj.address.focus();
return false;
}
}
</script>

</head>

<body>
<table border="1" align="center">

<form action="save.php" method="post" name="personalinfo" onSubmit="return validateform()" >


<tr>
<td>Student Number:</td>
<td><input type="text" name="studentno" /></td>
</tr>

<tr>
<td>Lastname:</td>
<td><input type="text" name="lastname" /></td>
</tr>

<tr>
<td>Firstname:</td>
<td><input type="text" name="firstname" /></td>
</tr>

<tr>
<td>Address:</td>
<td><input type="text" name="address" /></td>
</tr>

<tr>
<td><input type="submit" /></td>
<td>&nbsp;</td>
</tr>

</form>
</table>

</body>
</html>

Then after clicking submit button, you can add php code to POST or REQUEST data on the save.php file.
It's up to you if you will only display the data, or save the data to MySql Database.

No comments:

Post a Comment