Hey Gang, aside from mistakenly posting this in the Java Forum first it's my first time here so be gentle. I've been learning javascript through our local college and have run up against a problem. Maybe someone can help.
I'm using a simple validation script (external js) but continually get the same message "validation is not defined" and I can't get it to work for me.... Here's the code I'm using to access my form: -
function validation(document.forms.myForm) {
-
-
if (document.forms.myForm.e-mail.value.indexOf( "@" ) == -1)
-
-
{
-
alert( "Your e-mail address has been incorrectly entered. Please re-enter it" );
-
return false;
-
}
-
else
-
myForm.submit();
-
}
-
In addition to this, the reference I get when using FF javacript tool is that my first line in the html declaration <?xml version="1.0" encoding="UTF-8"?>
What am I missing...sigh. Lost in java hell...
DougB
13 2272
This will validate an email field: - <html><head><script type="text/javascript">function validate_email(field,alerttxt){with (field){apos=value.indexOf("@")dotpos=value.lastIndexOf(".")if (apos<1||dotpos-apos<2) {alert(alerttxt);return false}else {return true}}}function validate_form(thisform){with (thisform){if (validate_email(email,"Not a valid e-mail address!")==false) {email.focus();return false}}}</script></head><body><form action="submitpage.htm"onsubmit="return validate_form(this);"method="post">Email: <input type="text" name="email" size="30"><input type="submit" value="Submit"> </form></body></html>
I was lazy earlier here is your code changed up a bit for what you are looking for: - <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
<html xmlns="http://www.w3.org/1999/xhtml" >
-
<head>
-
<title>Untitled Page</title>
-
</head>
-
<script type="text/javascript">
-
function validation(form)
-
{
-
var Email = form.Email.value
-
if (Email.indexOf( "@" ) == -1)
-
{
-
alert( "Your e-mail address has been incorrectly entered. Please re-enter it" );
-
return false;
-
}
-
else
-
myForm.submit();
-
}
-
</script>
-
<body>
-
<form name="myForm" action="testing.htm" method="post">
-
<input type="text" name="Email" />
-
<input type="button" value="Submit" onclick="validation(this.form)" />
-
</form>
-
-
-
</body>
-
</html>
HTH,
Aric
Aric,
Many thanks, I'll try it later on tonight. Much appreciated...
DougB
Hey Aric,
Still not working (sorry I had to take off for a day or two here and no wireless where I was). Would it help you to know that I'm also using a javascript "reset" function in the form? I'm starting to pull out my hair..haha
DougB
Here's the entire code... -
<form name="myForm" id="myForm" action="mailto:me@myPlace.com?subject=Member Sales" method="post" enctype="text/plain">
-
-
<table>
-
<tr>
-
<td colspan="1">Name</td>
-
<td colspan="2"><input name="ID" type="text" /></td>
-
</tr>
-
<tr>
-
<td colspan="1">Address </td>
-
<td colspan="2"><input name="address" type="text" /></td>
-
</tr>
-
<tr>
-
<td colspan="1">City - Province</td>
-
<td colspan="2"><input name="city-prov" type="text" /></td></tr>
-
<tr>
-
<td colspan="1">Postal Code</td><td colspan="2"> <input name="postalcode" type="text" /></td>
-
</tr>
-
<tr>
-
<td colspan="1">Home Phone</td><td colspan="2"><input type="text" name="phone-number" /></td></tr><tr>
-
<td colspan="1">E-mail</td><td colspan="2"><input type="text" name="e-mail" /></td>
-
</tr>
-
-
<tr>
-
<td colspan="1">Item for Sale</td>
-
<td colspan="2">Description: <br /><input name="Sale Item" type="text" value="" /></td>
-
-
</tr>
-
<tr>
-
<td colspan="1">Price</td>
-
<td colspan="2"><input name="amount" type="text" value="" /></td>
-
</tr>
-
<tr>
-
<td colspan="1">Today's Date (M/D/Y) </td>
-
<td colspan="2"><input name="date" type="text" /></td>
-
</tr>
-
<tr>
-
<td colspan="3" align="center"><input type="submit" name="Submit" value="Submit" onclick="validation(this.form)" /></td>
-
</tr>
-
<tr>
-
<td colspan="3" align="center" onclick="javascript:document.forms.myForm.reset()"><input type="button" name="clear" value="Reset" /></td>
-
</tr>
-
</table>
-
</form>
-
In the <head> section of the html I reference this script with an external javascript - <script type="text/javascript"> src="java/validation.js"></script>function validation(form)
-
{
-
var Email = form.Email.value
-
if (Email.indexOf( "@" ) == -1)
-
{
-
alert( "Your e-mail address has been incorrectly entered. Please re-enter it" );
-
return false;
-
}
-
else
-
myForm.submit();
-
}
-
But I still can't get it to work...I'm having a D'oh moment here...please help if you can...
DougB
Anyone....help please
DougB
Greetings Gand,
I tried resetting the form values to reflect Email instead of E-mail from the form which is calls up the javascript. It didn't make any difference, can anyone help please...
DougB
up to my ears in frustration...sigh
The code I posted works for me anyone else test it? Copy and paste it to a new notepad document and name it test.htm then try.
Edit:
Doug: You have the field names mixed up I renamed the email field from e-mail to Email ( Sorry wrote that from scratch ). On your form you still have e-mail where in your Javascript you are using Email.
HTH,
Aric
Hoooooeeeeee....well here's the test page I did (minus the correct mailto: address of course). It allowed the send no problems without valdiation. This is the code I've used and you'll note that the Email called for in the javascript is now what is being sent by the form -
-
<html>
-
<head>
-
<title>Test</title>
-
<script type="text/javascript" src="validation.js"></script>
-
</head>
-
<body>
-
<form name="myForm" id="myForm" action="mailto:test@myplace.com?subject=Member Sales" method="post" enctype="text/plain">
-
-
<table>
-
<tr>
-
<td colspan="1">Name</td>
-
<td colspan="2"><input name="ID" type="text" /></td>
-
</tr>
-
<tr>
-
<td colspan="1">Address </td>
-
<td colspan="2"><input name="address" type="text" /></td>
-
</tr>
-
<tr>
-
<td colspan="1">City - Province</td>
-
<td colspan="2"><input name="city-prov" type="text" /></td></tr>
-
<tr>
-
<td colspan="1">Postal Code</td><td colspan="2"> <input name="postalcode" type="text" /></td>
-
</tr>
-
<tr>
-
<td colspan="1">Home Phone</td><td colspan="2"><input type="text" name="phone-number" /></td></tr><tr>
-
<td colspan="1">Email</td><td colspan="2"><input type="text" name="email" /></td>
-
</tr>
-
-
<tr>
-
<td colspan="1">Item for Sale</td>
-
<td colspan="2">Description: <br /><input name="Sale Item" type="text" value="" /></td>
-
-
</tr>
-
<tr>
-
<td colspan="1">Price</td>
-
<td colspan="2"><input name="amount" type="text" value="" /></td>
-
</tr>
-
<tr>
-
<td colspan="1">Today's Date (M/D/Y) </td>
-
<td colspan="2"><input name="date" type="text" /></td>
-
</tr>
-
<tr>
-
<td colspan="3" align="center"><input type="submit" name="Submit" value="Submit" onclick="validation(this.form)" /></td>
-
</tr>
-
<tr>
-
<td colspan="3" align="center" onclick="javascript:document.forms.myForm.reset()"><input type="button" name="clear" value="Reset" /></td>
-
</tr>
-
</table>
-
</form>
-
</body>
-
</html>
-
and here's the javascript file called "validation.js" -
function validation(form)
-
{
-
var Email = form.Email.value
-
if (Email.indexOf( "@" ) == -1)
-
{
-
alert( "Your e-mail address has been incorrectly entered. Please re-enter it" );
-
return false;
-
}
-
else
-
myForm.submit();
-
}
-
What am I missing.....help meeeeeeeeeeeeeeeeeee...Thanks for being persistent!
DougB
- <td colspan="1">Email</td><td colspan="2"><input type="text" name="email" /></td>
Needs to be - <td colspan="1">Email</td><td colspan="2"><input type="text" name="Email" /></td>
Look at the name of your email field and compare it to what you have called in Javascript.
I think this is what you were trying to achieve.
Ok so I didn't use the javascript include method so u will have to split the code how you want it. -
<script>
-
function validation(form)
-
{
-
var Email = document.getElementById("email").value
-
if (Email.indexOf( "@" ) == -1)
-
{
-
alert( "Your e-mail address has been incorrectly entered. Please re-enter it" );
-
return false;
-
}
-
else
-
myForm.submit();
-
}
-
</script>
-
<html>
-
<head>
-
<title>Test</title>
-
</head>
-
<body>
-
<form name="myForm" id="myForm" action="mailto:test@myplace.com?subject=Member Sales" method="post" enctype="text/plain">
-
-
<table>
-
<tr>
-
<td colspan="1">Name</td>
-
<td colspan="2"><input name="ID" type="text" /></td>
-
</tr>
-
<tr>
-
<td colspan="1">Address </td>
-
<td colspan="2"><input name="address" type="text" /></td>
-
</tr>
-
<tr>
-
<td colspan="1">City - Province</td>
-
<td colspan="2"><input name="city-prov" type="text" /></td></tr>
-
<tr>
-
<td colspan="1">Postal Code</td><td colspan="2"> <input name="postalcode" type="text" /></td>
-
</tr>
-
<tr>
-
<td colspan="1">Home Phone</td><td colspan="2"><input type="text" name="phone-number" /></td></tr><tr>
-
<td colspan="1">Email</td><td colspan="2"><input type="text" name="email" id="email" /></td>
-
</tr>
-
-
<tr>
-
<td colspan="1">Item for Sale</td>
-
<td colspan="2">Description: <br /><input name="Sale Item" type="text" value="" /></td>
-
-
</tr>
-
<tr>
-
<td colspan="1">Price</td>
-
<td colspan="2"><input name="amount" type="text" value="" /></td>
-
</tr>
-
<tr>
-
<td colspan="1">Today's Date (M/D/Y) </td>
-
<td colspan="2"><input name="date" type="text" /></td>
-
</tr>
-
<tr>
-
<td colspan="3" align="center"><input type="button" name="Submit" value="Submit" onclick="validation(this.form)" /></td>
-
</tr>
-
<tr>
-
<td colspan="3" align="center" onclick="javascript:document.forms.myForm.reset()"><input type="button" name="clear" value="Reset" /></td>
-
</tr>
-
</table>
-
</form>
-
</body>
-
</html>
-
iam_clint...
many thanks, works like a charm. I also see my original mistake in not calling it from an id too...thanks again! Also note to Aric many thanks as well...
Cheers Guys!
DougB
Glad you finally got it remember most languages are Case Sensitive
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Stefan Richter |
last post by:
Hi, after coding for days on stupid form validations -
Like:
strings (min / max length), numbers(min / max value), money(min / max
value), postcodes(min / max value), telefon numbers,
email...
|
by: dmcconkey |
last post by:
Hi folks,
I have a client with four websites. Each site has a contact form that
is identical. They all have "required" fields validated through a
JavaScript onSubmit() function. Upon validation,...
|
by: Neo Chou |
last post by:
Greetings!
I have a question about constant.
I have a page like:
----------------------------------------------------------------------
<%
Const adInteger = 3 'copied from adovbs.inc
Const...
|
by: Rajesh Jain |
last post by:
I Have 2 separate schemas.
--------------Schema 1 is defined as below-----------
<xs:schema targetNamespace="http://Schemas/1" xmlns="http://Schemas/1" xmlns:xs="http://www.w3.org/2001/XMLSchema"...
|
by: Iain A. Mcleod |
last post by:
Hi
I'm stuck with the following schema validation problem in VS.NET 2003:
I have two types of xml document and related schema:
project and projectCollection.
A projectcollection is just a set...
|
by: Tim Marshall |
last post by:
From http://www.mvps.org/access/tencommandments.htm
9th item:
Thou shalt not use "SendKeys", "Smart Codes" or "GoTo" (unless the GoTo
be part of an OnError process) for these will lead you...
|
by: Damian Burrin |
last post by:
Hi guy's i'm v new to this and probably getting this wrapped right round my
head, but why can't i use something like wc3 to validate this.
-----------------XML---------------------------
<?xml...
|
by: Lost Student |
last post by:
Hello guys
Any help that you can offer would be greatly appreciated. I am nearing
the end of a C++ class and am so lost.
The following is my assignment and what I have so far. Please help
...
|
by: Chris |
last post by:
Hi,
I have a form for uploading documents and inserting the data into a mysql
db. I would like to validate the form. I have tried a couple of Javascript
form validation functions, but it...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |