PDA

View Full Version : Oops, you forget an e-mail address


Thee Gandalf
12-22-2003, 05:42 PM
Hi,

I have a form with an several fields in it, but I need a codelette to let the user know if they forgot to enter an e-mail address (if nothing entered in that field, then the form can't be sent).

<td class="td-bgcolor" align="left">E-mail:</td><td class="td-bgcolor-2" align="left" colspan="5"><input type="text" name="email"></td>

Thanks,
Gändälf
:D

Willy Duitt
12-22-2003, 09:52 PM
Here's one way.
It not only checks if something is entered.
But checks for the @ symbol as well.

<script type="text/javascript">
<!--//
function chkIt() {
var from = document.form1.email.value;
if (from.indexOf("@") == -1){
alert('You must enter a valid email address');
document.form1.email.value='';
document.form1.email.focus();
return false;
}
document.form1.submit();
}
//-->
</script>
</HEAD>

<BODY>
<form name="form1" method="post" action="mailto:">
<input type="text" name="email"><br>
<input type="button" value="Submit" onclick="chkIt()">
</form>

.....Willy

Edit: Added document.form1.email.value='';