473,396 Members | 1,987 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.

I'm Lost ....Help. Validation not defined...

14
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:
Expand|Select|Wrap|Line Numbers
  1. function validation(document.forms.myForm) { 
  2.  
  3. if (document.forms.myForm.e-mail.value.indexOf( "@" ) == -1)
  4.  
  5. {
  6. alert( "Your e-mail address has been incorrectly entered. Please re-enter it" );
  7. return false;
  8. }
  9. else
  10. myForm.submit();
  11. }
  12.  
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
Nov 3 '06 #1
13 2272
AricC
1,892 Expert 1GB
This will validate an email field:
Expand|Select|Wrap|Line Numbers
  1. <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>
Nov 4 '06 #2
AricC
1,892 Expert 1GB
I was lazy earlier here is your code changed up a bit for what you are looking for:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" >
  3. <head>
  4.     <title>Untitled Page</title>
  5. </head>
  6. <script type="text/javascript">
  7. function validation(form) 
  8. {
  9. var Email = form.Email.value
  10. if (Email.indexOf( "@" ) == -1)
  11. {
  12. alert( "Your e-mail address has been incorrectly entered. Please re-enter it" );
  13. return false;
  14. }
  15. else
  16. myForm.submit();
  17. }
  18. </script>
  19. <body>
  20. <form name="myForm" action="testing.htm" method="post">
  21. <input type="text" name="Email" />
  22. <input type="button" value="Submit" onclick="validation(this.form)" />
  23. </form>
  24.  
  25.  
  26. </body>
  27. </html>
HTH,
Aric
Nov 4 '06 #3
DougB
14
Aric,

Many thanks, I'll try it later on tonight. Much appreciated...

DougB
Nov 4 '06 #4
DougB
14
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
Nov 5 '06 #5
DougB
14
Here's the entire code...

Expand|Select|Wrap|Line Numbers
  1. <form name="myForm" id="myForm" action="mailto:me@myPlace.com?subject=Member Sales" method="post" enctype="text/plain">
  2.  
  3.             <table>
  4.                 <tr>
  5.                   <td colspan="1">Name</td>
  6.                   <td colspan="2"><input name="ID" type="text" /></td>
  7.                 </tr>
  8.                 <tr>
  9.                   <td colspan="1">Address </td>
  10.         <td colspan="2"><input name="address" type="text" /></td>
  11.         </tr>
  12.         <tr>
  13.         <td colspan="1">City - Province</td>
  14.         <td  colspan="2"><input name="city-prov" type="text" /></td></tr>
  15. <tr>
  16. <td colspan="1">Postal Code</td><td colspan="2"> <input name="postalcode" type="text" /></td>
  17.                 </tr>
  18.                 <tr>
  19.                   <td colspan="1">Home Phone</td><td colspan="2"><input type="text" name="phone-number" /></td></tr><tr>
  20.                   <td colspan="1">E-mail</td><td colspan="2"><input type="text" name="e-mail"  /></td>
  21.                 </tr>
  22.  
  23.                 <tr>
  24.                   <td colspan="1">Item for Sale</td>
  25.                   <td colspan="2">Description: <br /><input name="Sale Item" type="text" value="" /></td>
  26.  
  27.                 </tr>
  28.                 <tr>
  29.         <td colspan="1">Price</td>
  30.                   <td colspan="2"><input name="amount" type="text" value="" /></td>
  31.                 </tr>
  32.                 <tr>
  33.                   <td colspan="1">Today's Date (M/D/Y) </td>
  34.                   <td colspan="2"><input name="date" type="text"  /></td>
  35.                 </tr>
  36.                 <tr>
  37.                   <td colspan="3" align="center"><input type="submit" name="Submit" value="Submit" onclick="validation(this.form)" /></td>
  38.                 </tr>
  39.                 <tr>
  40.                   <td colspan="3" align="center" onclick="javascript:document.forms.myForm.reset()"><input type="button" name="clear" value="Reset" /></td>
  41.                 </tr>
  42.                </table>
  43.       </form>
  44.  
In the <head> section of the html I reference this script with an external javascript

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript"> src="java/validation.js"></script>function validation(form) 
  2. {
  3. var Email = form.Email.value
  4. if (Email.indexOf( "@" ) == -1)
  5. {
  6. alert( "Your e-mail address has been incorrectly entered. Please re-enter it" );
  7. return false;
  8. }
  9. else
  10. myForm.submit();
  11. }
  12.  
But I still can't get it to work...I'm having a D'oh moment here...please help if you can...

DougB
Nov 6 '06 #6
DougB
14
Anyone....help please

DougB
Nov 6 '06 #7
DougB
14
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
Nov 7 '06 #8
AricC
1,892 Expert 1GB
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
Nov 7 '06 #9
DougB
14
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

Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3. <head>
  4. <title>Test</title>
  5. <script type="text/javascript" src="validation.js"></script>
  6. </head>
  7. <body>
  8. <form name="myForm" id="myForm" action="mailto:test@myplace.com?subject=Member Sales" method="post" enctype="text/plain">
  9.  
  10.             <table>
  11.                 <tr>
  12.                   <td colspan="1">Name</td>
  13.                   <td colspan="2"><input name="ID" type="text" /></td>
  14.                 </tr>
  15.                 <tr>
  16.                   <td colspan="1">Address </td>
  17.         <td colspan="2"><input name="address" type="text" /></td>
  18.         </tr>
  19.         <tr>
  20.         <td colspan="1">City - Province</td>
  21.         <td  colspan="2"><input name="city-prov" type="text" /></td></tr>
  22. <tr>
  23. <td colspan="1">Postal Code</td><td colspan="2"> <input name="postalcode" type="text" /></td>
  24.                 </tr>
  25.                 <tr>
  26.                   <td colspan="1">Home Phone</td><td colspan="2"><input type="text" name="phone-number" /></td></tr><tr>
  27.                   <td colspan="1">Email</td><td colspan="2"><input type="text" name="email"  /></td>
  28.                 </tr>
  29.  
  30.                 <tr>
  31.                   <td colspan="1">Item for Sale</td>
  32.                   <td colspan="2">Description: <br /><input name="Sale Item" type="text" value="" /></td>
  33.  
  34.                 </tr>
  35.                 <tr>
  36.         <td colspan="1">Price</td>
  37.                   <td colspan="2"><input name="amount" type="text" value="" /></td>
  38.                 </tr>
  39.                 <tr>
  40.                   <td colspan="1">Today's Date (M/D/Y) </td>
  41.                   <td colspan="2"><input name="date" type="text"  /></td>
  42.                 </tr>
  43.                 <tr>
  44.                   <td colspan="3" align="center"><input type="submit" name="Submit" value="Submit" onclick="validation(this.form)" /></td>
  45.                 </tr>
  46.                 <tr>
  47.                   <td colspan="3" align="center" onclick="javascript:document.forms.myForm.reset()"><input type="button" name="clear" value="Reset" /></td>
  48.                 </tr>
  49.                </table>
  50.       </form>
  51. </body>
  52. </html>
  53.  
and here's the javascript file called "validation.js"
Expand|Select|Wrap|Line Numbers
  1. function validation(form) 
  2. {
  3. var Email = form.Email.value
  4. if (Email.indexOf( "@" ) == -1)
  5. {
  6. alert( "Your e-mail address has been incorrectly entered. Please re-enter it" );
  7. return false;
  8. }
  9. else
  10. myForm.submit();
  11. }
  12.  
What am I missing.....help meeeeeeeeeeeeeeeeeee...Thanks for being persistent!

DougB
Nov 7 '06 #10
AricC
1,892 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. <td colspan="1">Email</td><td colspan="2"><input type="text" name="email"  /></td>
Needs to be

Expand|Select|Wrap|Line Numbers
  1. <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.
Nov 7 '06 #11
iam_clint
1,208 Expert 1GB
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.

Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function validation(form) 
  3. {
  4. var Email = document.getElementById("email").value
  5. if (Email.indexOf( "@" ) == -1)
  6. {
  7. alert( "Your e-mail address has been incorrectly entered. Please re-enter it" );
  8. return false;
  9. }
  10. else
  11. myForm.submit();
  12. }
  13. </script>
  14. <html>
  15. <head>
  16. <title>Test</title>
  17. </head>
  18. <body>
  19. <form name="myForm" id="myForm" action="mailto:test@myplace.com?subject=Member Sales" method="post" enctype="text/plain">
  20.  
  21.             <table>
  22.                 <tr>
  23.                   <td colspan="1">Name</td>
  24.                   <td colspan="2"><input name="ID" type="text" /></td>
  25.                 </tr>
  26.                 <tr>
  27.                   <td colspan="1">Address </td>
  28.         <td colspan="2"><input name="address" type="text" /></td>
  29.         </tr>
  30.         <tr>
  31.         <td colspan="1">City - Province</td>
  32.         <td  colspan="2"><input name="city-prov" type="text" /></td></tr>
  33. <tr>
  34. <td colspan="1">Postal Code</td><td colspan="2"> <input name="postalcode" type="text" /></td>
  35.                 </tr>
  36.                 <tr>
  37.                   <td colspan="1">Home Phone</td><td colspan="2"><input type="text" name="phone-number" /></td></tr><tr>
  38.                   <td colspan="1">Email</td><td colspan="2"><input type="text" name="email" id="email"  /></td>
  39.                 </tr>
  40.  
  41.                 <tr>
  42.                   <td colspan="1">Item for Sale</td>
  43.                   <td colspan="2">Description: <br /><input name="Sale Item" type="text" value="" /></td>
  44.  
  45.                 </tr>
  46.                 <tr>
  47.         <td colspan="1">Price</td>
  48.                   <td colspan="2"><input name="amount" type="text" value="" /></td>
  49.                 </tr>
  50.                 <tr>
  51.                   <td colspan="1">Today's Date (M/D/Y) </td>
  52.                   <td colspan="2"><input name="date" type="text"  /></td>
  53.                 </tr>
  54.                 <tr>
  55.                   <td colspan="3" align="center"><input type="button" name="Submit" value="Submit" onclick="validation(this.form)" /></td>
  56.                 </tr>
  57.                 <tr>
  58.                   <td colspan="3" align="center" onclick="javascript:document.forms.myForm.reset()"><input type="button" name="clear" value="Reset" /></td>
  59.                 </tr>
  60.                </table>
  61.       </form>
  62. </body>
  63. </html>
  64.  
Nov 7 '06 #12
DougB
14
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
Nov 7 '06 #13
AricC
1,892 Expert 1GB
Glad you finally got it remember most languages are Case Sensitive
Nov 8 '06 #14

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

Similar topics

21
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...
8
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,...
4
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...
0
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"...
4
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...
37
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...
5
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...
6
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 ...
27
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
0
agi2029
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,...

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.