Hello,
Can one of you javascript wizards help out a newbie, please?
I’ve got a formHandler that is supposed to check for a good email address and name in the form after clicking the submit link and display a status error message above the form if either the E-mail and/or Name fields are blank, but instead the page does nothing.
I think that the Submit link in the code below is probably the root of the problem:
<a href="javascript:;" onClick="form.submit()">Submit</a>
I’ve got a lot to learn and would greatly appreciate your help.
Thanks in advance for your reply.
DP
javascript:
<script language="JavaScript" type="text/JavaScript"><!--
// dynamic forms
// ©2005
// browser check
var w3c = document.getElementById ? true : false;
var iex = document.all ? true : false;
var ns4 = document.layers ? true : false;
// info layer
var idlayer = 'status';
function _show(text, mode) {
if (w3c) {
if(text) {
document.getElementById(idlayer).style.visibility = 'visible';
document.getElementById(idlayer).innerHTML = '<span class="' + ((mode) ? 'infomsg' : 'errormsg') + '">' + text + '</span>';
} else {
document.getElementById(idlayer).style.visibility = 'hidden';
}
} else if (iex) {
if(text) {
document.all[idlayer].style.visibility = 'visible';
document.all[idlayer].innerHTML = '<span class="' + ((mode) ? 'infomsg' : 'errormsg') + '">' + text + '</span>';
} else {
document.all[idlayer].style.visibility = 'hidden';
}
} else if (ns4) {
var x = document.layers[idlayer];
var text2 = '<p class="infomsg">' + document.layers[named].innerHTML + '</p>';
x.document.open();
x.document.write(text2);
x.document.close();
}
}
function _formHandler(frm) {
// document.forms.form.sendata.disabled = true;
var goodEmail = frm.re_Email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.go v)|(\.org)|(\..{2,2}))$)\b/gi);
var goodName = frm.Name.value;
if (!goodEmail) {
_show('Your email address is required!',1);
frm.re_Email.focus();
return false;
} else if (!goodName) {
_show('Your name is required!',1);
frm.Name.focus();
return false;
} else {
return true;
}
}
// --></script>
Form on html page:
<div class="t3"><img src="images/5_text3.gif" alt="Contact Form" width="124" height="14"> &n bsp; <span id="status" align="center">Complete for appointment</span>
<br>
<form name="form" method="post" action="formprocessorpro.php" class="form" onSubmit="return _formHandler(this);">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" width="176">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" height="24" width="38"><img src="images/spacer.gif" alt="" width="5px" height="3px"><br><img src="images/spacer.gif" alt="" width="4px" height="2px">Name:</td>
<td valign="top"><input type="text" name="Name"></td>
</tr>
<tr>
<td valign="top" height="24"><img src="images/spacer.gif" alt="" width="5px" height="3px"><br>Phone:</td>
<td valign="top"><input type="text" name="Telephone"></td>
</tr>
<tr>
<td valign="top"><img src="images/spacer.gif" alt="" width="5px" height="3px"><br><img src="images/spacer.gif" alt="" width="2px" height="2px">E-mail:</td>
<td valign="top"><input type="text" name="re_Email"></td>
</tr>
</table>
</td>
<td valign="top"><img src="images/spacer.gif" alt="" width="5px" height="3px"><br>Message:<br>
<textarea name="Message" cols="2" rows="2"></textarea>
</td>
</tr>
</table>
<div>
<a href="javascript:;" onClick="_show(null,0);form.reset();return false;">Reset</a>
<a href="javascript:;" onClick="form.submit()">Submit</a>
</div>
</form>
</div>
</td>