473,396 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Idiot needs javascript help with formHandler, please

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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;<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>
Sep 12 '06 #1
1 2153
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.


-Ramesh
Nov 3 '06 #2

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

Similar topics

4
by: dmiller23462 | last post by:
I'm trying to create a submission page for users to request PC/LAN Access....If they select "Yes" in the field asking about if they need Non Standard Software, I want several other HTML fields to...
11
by: Peter Foti | last post by:
Hi all, I have a form that contains a 2 column table. In the left column is the description for a particular input (ie - "First Name", "Last Name", "Phone Number", etc.). In the right column...
9
by: YZK | last post by:
Hello. I'm not a Web developer, just a user, and I think I may have somehow messed myself up majorly. I'm not quite sure how. Right now, javascript used by websites I go to either does not work at...
4
by: ...D. | last post by:
OK. I am halfway decent with HTML. Now I want to try javascript for some things that HTML cannot do. I have looked over a tutorial & all. What I want to do is create a button, that when...
8
by: Yeah | last post by:
I wish to use a drop box where each Option will not take the user to a web page - but a certain location on the same page the drop box exists. For example, Option 1 would take the user to "Chapter...
12
by: clintonG | last post by:
I can't tell you how frustrated I get when going to a web developer's website and observing he or she is an idiot that has not grasped the most fundamental element of usability: page title naming...
2
by: sgMuser | last post by:
Hi, I am not a good developer of Javascript codes. Needs this help to make some modification to this famous free javascript from Anarchos. i am using this in one of my webpage. What it does is,...
5
by: mk | last post by:
Greetings all - im new to this newsgroup so pls dont flame me :p I need some help! Please view the html below in a browser. Or goto this url -http://firebrain.co.uk/java-problem.htm (Assuming...
1
by: jianxin9 | last post by:
Hi, I have an ajax powered tabs box that has a javascript drop-down search menu in the first tab. When I click on another tab, and go back to the first tab I have to refresh the page to get the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.