This is a simple javascript to validate our form’s page like register form or login form.
And this is the scripts . put this script in head :
<script language=”JavaScript”>
<!–
function validateForm()
{
var okSoFar=true
with (document.form)
{
if (name.value==”" && okSoFar)
{
okSoFar=false
alert(“Insert Your Name”)
name.focus()
}
if (address.value==”" && okSoFar)
{
okSoFar=false
alert(“Insert Your Address”)
address.focus()
}
if (password1.value !== password2.value && okSoFar)
{
okSoFar=false
alert(“Password do not match, please repeat”)
password2.focus()
}
if (okSoFar==true) submit();
}
}
// –>
</script>
After we put that script we must create the form with 4 input form according the javascript, in this case we should create name, address, password1 and password2 input form.
And the last for submit button. we must insert this script : onclick=”javascript:validateForm()”
for ex ;
<input name=”submit” type=”submit” onclick=”javascript:validateForm()” >
If Done, when the user do not type anythink word, the error message pop up will a rise.