Script Categories

Forms >>> Only One Field.

The 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.

Please enter your name or your email address.

Name Email

Add the below code to the <body> section of your page:

<script language="javascript" type="text/javascript">
/* Visit for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin
function checkFields() {
name =;
email =;

if ((name == "") && (email == "") ) {
alert("Please enter your name or your email address.");
return false;
else return true;
//  End -->
<form action="" name=submitform onSubmit="return checkFields()">

Please enter your name or your email address.<br><br>
<table border=0>
align=center><input type=text name=name value="" onFocus="'';" size=10></td>
align=center><input type=text name=email value="" onFocus="'';" size=10></td>
colspan=3 align=center><input type=submit value="Submit!"></td>

JavaScript Editor Get Advanced
JavaScript and Ajax Editor,
Validator and Debugger!

1st JavaScript Editor.

Code was highlighted by 1st JavaScript Editor (The Best JavaScript Editor!).