»
EnglishFrenchVietnamese

Print - Only One Field - JavaScriptBank.com

Full version: jsB@nk » Form » Validation » Only One Field
URL: http://www.javascriptbank.com/only-one-field.html

Only One Field © JavaScriptBank.comThe visitor must fill in either one of two fields, their name or email address. If they click in either box the other box's value is erased. Ensures that when the form is submitted only one field contains a value. Also contains validation that makes sure both fields are not empty.

Full version: jsB@nk » Form » Validation » Only One Field
URL: http://www.javascriptbank.com/only-one-field.html



JavaScript
<SCRIPT LANGUAGE="JavaScript"><!-- Beginfunction checkFields() {name = document.submitform.name.value;email = document.submitform.email.value;if ((name == "") && (email == "") ) {alert("Please enter your name or your email address.");return false;}else return true;}//  End --></script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<form action="http://www.your-web-site-address-here.com/script.cgi" name=submitform onSubmit="return checkFields()">Please enter your name or your email address.<br><br><table border=0><tr><td align=center>Name</td><td> </td><td align=center>Email</td></tr><tr><td align=center><input type=text name=name value="" onFocus="document.submitform.email.value='';" size=10></td><td align=center>Or...</td><td align=center><input type=text name=email value="" onFocus="document.submitform.name.value='';" size=10></td></tr><tr><td colspan=3 align=center><input type=submit value="Submit!"></td></tr></table></form><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->