JavaScript Required Field v.3

 

This script will remind you by occupying the value of a form field, if you do not fill in a required field. Very useful, because other then the alert function, the reminder will stay displayed until the user fills in the required field.

If you decide you want to use or alter the script to suit your needs, please give your support and leave a link to this site,thanks.



Example

Your name (*)

Your E-mail address (*)

       (*) Required

 

Script Source

 

<The form >

<form action="" method="post" name="form1" onsubmit="return checkForm();">
<div></div>
<fieldset>
<legend>Your name</legend><p>
<input type="text" name="name" size="20">
</p></fieldset>
<fieldset>
<legend>Your E-mail address</legend><p>
<input type="text" name="email" size="25">
</p></fieldset>
<p><input type="submit" value="Try it!"><input type="reset" /></P>
</form>

 

<The JavaScript >

<script type="text/javascript">

<!-- Hide from old browsers

// Script by www.wizzardweb.co.uk
// If you are using this code please leave
// a link to www.wizzardweb.co.uk

function checkForm() {

if (document.form1.name.value == "" || document.form1.name.value == "** Required **") {

document.form1.name.value="** Required **";
document.form1.name.select();
document.form1.name.focus();
return false;

}

else if (document.form1.email.value == "" || document.form1.email.value == "** Required **") {

document.form1.email.value="** Required **";
document.form1.email.select();
document.form1.email.focus();
return false;

}
else
{

return true;

}
}
//-->
</script>

 

Please let me know if this script was helpful to you.

[rating]