By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,568 Members | 1,196 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,568 IT Pros & Developers. It's quick & easy.

Idiot needs javascript help with formHandler, please

P: 1

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.



<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>';;

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);
return false;
} else if (!goodName) {
_show('Your name is required!',1);
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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;<span id="status" align="center">Complete for appointment</span>
<form name="form" method="post" action="formprocessorpro.php" class="form" onSubmit="return _formHandler(this);">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<td valign="top" width="176">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<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>
<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>
<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>
<td valign="top"><img src="images/spacer.gif" alt="" width="5px" height="3px"><br>Message:<br>
<textarea name="Message" cols="2" rows="2"></textarea>
<a href="javascript:;" onClick="_show(null,0);form.reset();return false;">Reset</a>
<a href="javascript:;" onClick="form.submit()">Submit</a>
Sep 12 '06 #1
Share this Question
Share on Google+
1 Reply

P: 15
hi dreamlab

I think i fixed what you were trying to do.

Insert this within the script tags at the top

Expand|Select|Wrap|Line Numbers
  1. function validate_form(frm) {
  2.     if (_formHandler(frm))
  3.      document.form_1.submit(frm);
  4. }
rename the form to form_1 and remove the onsubmit attribute and make it like this

Expand|Select|Wrap|Line Numbers
  1. <form name="form_1" method="post" action="formprocessorpro.php" class="form">
and finally at the bottom at the place where you had those two links, replace them with this

Expand|Select|Wrap|Line Numbers
  1. <a href="javascript:;" onClick="_show(null,0);form_1.reset();return false;">Reset</a>
  2. <a onClick="validate_form(form_1);">Submit</a>
-Try It and please reply if it works or not.

Willing to help you more if needed.

Nov 3 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.