JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 19th, 2012, 08:03 PM
n3pl3x27 n3pl3x27 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 13 n3pl3x27 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 27 m 9 sec
Reputation Power: 0
Javascript Validation error!

I have jquery, implementing AJAX and trying to validate the input in form, but I got into error. I think, it is due to having too much javascript, I don't know. I don't know much about Javascript.
Here is my code:

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Main page</title>
Javascript Code:
Original - Javascript Code
  1.  
  2.     <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
  3.     <script src="http://code.jquery.com/jquery-1.8.2.js"></script>
  4.     <script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
  5.     <link rel="stylesheet" href="/resources/demos/style.css" />
  6.     <script>
  7.         $(function() {
  8.             $( "#accordion" ).accordion();
  9.         });
  10.     </script>

<?php
include('includes/header.inc');
include('includes/leftColumn.inc');
?>
</head>
<body>

<form>
...
........
............
Javascript Code:
Original - Javascript Code
  1.  
  2. <script>
  3.                         /************************************
  4.                             *Below is the script for AJAX:
  5.                            **********************************/
  6.                            function showHint(str)
  7.                            {
  8.                            if (str.length==0)
  9.                              {
  10.                              document.getElementById("txtHint").innerHTML="";
  11.                              return;
  12.                              }
  13.                            if (window.XMLHttpRequest)
  14.                              {// code for IE7+, Firefox, Chrome, Opera, Safari
  15.                              xmlhttp=new XMLHttpRequest();
  16.                              }
  17.                            else
  18.                              {// code for IE6, IE5
  19.                              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  20.                              }
  21.                            xmlhttp.onreadystatechange=function()
  22.                              {
  23.                              if (xmlhttp.readyState==4 && xmlhttp.status==200)
  24.                                {
  25.                                document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
  26.                                }
  27.                              }
  28.                            xmlhttp.open("GET","gethint.php?q="+str,true);
  29.                            xmlhttp.send();
  30.                            }
  31.                     </script>

Topping:
<p><b>Start typing a topping name in the input field below:</b></p>
<input type="text" onkeyup="showHint(this.value)">
<p>Suggestions: <span id="txtHint"></span></p>
</p>
</div>
.........
........
Javascript Code:
Original - Javascript Code
  1.  
  2. <script>
  3.             /**************************
  4.             *Validation script:
  5.            *************************/
  6.            function validateForm()
  7.            {
  8.            var x=document.forms["myForm"]["fName"].value;
  9.            if (x==null || x=="")
  10.              {
  11.              alert("First name must be filled out");
  12.              return false;
  13.              }
  14.              {
  15.            var x=document.forms["myForm"]["lName"].value;
  16.            if (x==null || x=="")
  17.              {
  18.              alert("Last name must be filled out");
  19.              return false;
  20.              }
  21.            } 
  22.         </script>

<input type="submit" value="Submit Order" onsubmit="return validateForm()" />
</form>
........

...........

But javascript validator is not working. it passess somehow. can't solve this problem.

Any suggestion?

Reply With Quote
  #2  
Old December 20th, 2012, 04:06 AM
Winters Winters is offline
Super Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jul 2003
Posts: 3,932 Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 13 h 8 m 31 sec
Reputation Power: 2632
The '$this' in the submit handler is meaningless and will throw an error.
The '$this' is pointless as you are referencing the form elements with the 'x' variable anyway.

'return error' should not be there. What was it intended to do?

At a guess I would say you have gotten the syntax between pure Javascript and jQuery confused a bit. Remove both instances of '$this' and the 'return error' line and see if that helps.

Also, in the future please wrap your code within [highlight=Javascript] [/highlight] or [code] [/code] tags, as it makes it much easier to read.
__________________
[PHP] | [Perl] | [Python] | [Java] != [JavaScript] | [XML] | [ANSI C] | [C++] | [LUA] | [MySQL] | [FirebirdSQL] | [PostgreSQL] | [HTML] | [XHTML] | [CSS]

W3Fools - A W3Schools Intervention.

Reply With Quote
  #3  
Old December 20th, 2012, 10:28 AM
n3pl3x27 n3pl3x27 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 13 n3pl3x27 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 27 m 9 sec
Reputation Power: 0
Oh! I am sorry, I post after being depressed with my code. ($this) and 'return error' was not meant to be there, it was i who was playing with that but forget to delete while posting. Now, I have edited it.
is my jquery messing with my javascript validation at the bottom?

thank you for your time.

Reply With Quote
  #4  
Old December 20th, 2012, 10:49 AM
Winters Winters is offline
Super Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jul 2003
Posts: 3,932 Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 13 h 8 m 31 sec
Reputation Power: 2632
Count your curly bracers.
Javascript Code:
Original - Javascript Code
  1. function validateForm() {
  2.     var f = document.forms["myForm"], fError = '';
  3.  
  4.     var fn = f["fName"].value;
  5.     if (fn == null || fn == '') {
  6.         fError += "* First name\n";
  7.     }
  8.  
  9.     var ln = f["lName"].value;
  10.     if (ln == null || ln == '') {
  11.         fError += "* Last name\n";
  12.     }
  13.  
  14.     if (fError) {
  15.         fError = "ERROR: Please enter values for the following fields:-\n\n" + fError;
  16.         alert(fError);
  17.         return false;
  18.     }
  19. }

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Javascript Validation error!

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap