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



Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 8th, 2012, 09:03 PM
KallumTanton KallumTanton is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 4 KallumTanton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 13 sec
Reputation Power: 0
Unhappy Need Help Debugging Script/Error in Script - Form Validation Error - Form Seemingly Ignores Return Value

Hi there, I'm reasonably new to JavaScript so I'm finding it hard to see where I went wrong here.
I have two forms on a .php page, they both validate through their own JavaScript functions before performing the actions (going to another .php page). One form is a PayPal login form, the other a credit card detail form, the idea is a user chooses one or the other. Neither form is meant to save or use any of these details, it's a school project, it just needs to validate. However, when validating, error messages appear next to empty fields as expected, but the forms submit and the action continues anyway, even though my validation script specifically says to return false if there are errors. I've searched Google and forums for about 3 hours now, I hate disturbing people but if this is ever going to work I think this is my only choice, sorry peeps but any help would be great appreciated!

My code:
<head>
<script type="text/javascript" >

function validatePaypal()
{
var x=document.forms["paypalform"]["paypalusername"].value;
var y=0;

if (y==0)
{
document.getElementById("usererror", "passerror").innerHTML="";
}

if (x==null || x=="")
{
document.getElementById("usererror").innerHTML="Please enter your PayPal username";
y='y+1';
}
x=document.forms["paypalform"]["paypalpassword"].value;
if (x==null || x=="")
{
document.getElementById("passerror").innerHTML="Please enter your PayPal password";
y='y+1';
}
if (y==0)
{
return true;
}
else {
return false;
}
}

function validateCard()
{
var x=document.forms["cardform"]["cardtypeselect"].value;
var y=0;
var z=0;

if (y==0)
{
document.getElementById("cardtypeselect", "cardname", "cardnumber", "startdatemonth", "startdateyear", "enddatemonth", "enddateyear", "cardsortcode", "cardsecurecode").innerHTML="";
}

if (x==null || x=="" || x=="Select card...")
{
document.getElementById("cardtypeselecterror").innerHTML="Please select your card";
y='y+1';
}
x=document.forms["cardform"]["cardname"].value;
if (x==null || x=="")
{
document.getElementById("cardnameerror").innerHTML="Please enter the name exactly as it is on your card";
y='y+1';
}
x=document.forms["cardform"]["cardnumber"].value;
if (x==null || x=="")
{
document.getElementById("cardnumbererror").innerHTML="Please enter your card number without the spaces";
y='y+1';
}
x=document.forms["cardform"]["cardsecurecode"].value;
if (x==null || x=="" || x.length!=3)
{
document.getElementById("cardsecurecodeerror").innerHTML="Please enter your secure code";
y='y+1';
}
if (y==0)
{
return true;
}
else {
return false;
}
}
</script>
</head>
<body>
<form action="/tickets/confirm.php" method="post" name="paypalform" enctype="multipart/form-data" onsubmit="validatePaypal()">
<p>
<label for="paypalusername">PayPal Username</label>
<input name="paypalusername" type="text" id="paypalusername" tabindex="1" size="32" /><b id="usererror">&nbsp;</b>
</p>
<p>
<label for="paypalpassword">PayPal Password</label>
<input name="paypalpassword" type="password" id="paypalpassword" tabindex="2" size="32" /><b id="passerror">&nbsp;</b>
</p>
<p>
<input type="submit" name="submit" id="submit" value="Next" tabindex="3" />
</p>
</form>

<form action="/tickets/confirm.php" method="post" name="cardform" enctype="multipart/form-data" onsubmit="validateCard()">
<p><img src="/images/cardtype.gif" width="314" height="25" alt="cardtype" />
</p>
<p>
<label for="cardtypeselect">Select Your Card*</label>

<select name="cardtypeselect" id="cardtypeselect" tabindex="1">
<option selected="selected">Select card...</option><b id="cardtypeselecterror"></b>
<option>Visa</option>
<option>MasterCard</option>
<option>VisaDebit</option>
<option>Solo</option>
<option>Maestro</option>
<option>VisaElectron</option>
<option>AmericanExpress</option>
</select>
</p>
<p>
<label for="cardname">Name on Card*</label><b id="cardnameerror">&nbsp;</b>

<input name="cardname" type="text" id="cardname" tabindex="2" size="32" />
</p>
<p>
<label for="cardnumber">Card Number*</label>

<input name="cardnumber" type="text" id="cardnumber" tabindex="3" value="XXXXXXXXXXXXXXXX" size="32" maxlength="16" /><b id="cardnumbererror">&nbsp;</b>
</p>
<p>Start Date (if applicable)
<label for="startdatemonth"></label>
<select name="startdatemonth" id="startdatemonth" tabindex="4">
<option selected="selected">Select month...</option>
<option>Jan</option>
<option>Feb</option>
<option>Mar</option>
<option>Apr</option>
<option>May</option>
<option>Jun</option>
<option>Jul</option>
<option>Aug</option>
<option>Sep</option>
<option>Oct</option>
<option>Nov</option>
<option>Dec</option>
</select>
<select name="startdateyear" id="startdateyear" tabindex="5">
<option selected="selected">Select year...</option>
<option>2000</option>
<option>2001</option>
<option>2002</option>
<option>2003</option>
<option>2004</option>
<option>2005</option>
<option>2006</option>
<option>2007</option>
<option>2008</option>
<option>2009</option>
<option>2010</option>
<option>2011</option>
<option>2012</option>
</select>
</p>
<p>End Date (if applicable)
<label for="enddatemonth"></label>
<select name="enddatemonth" id="enddatemonth" tabindex="6">
<option selected="selected">Select month...</option>
<option>Jan</option>
<option>Feb</option>
<option>Mar</option>
<option>Apr</option>
<option>May</option>
<option>Jun</option>
<option>Jul</option>
<option>Aug</option>
<option>Sep</option>
<option>Oct</option>
<option>Nov</option>
<option>Dec</option>
</select>
<select name="enddateyear" id="enddateyear" tabindex="7">
<option selected="selected">Select year...</option>
<option>2012</option>
<option>2013</option>
<option>2014</option>
<option>2015</option>
<option>2016</option>
<option>2017</option>
<option>2018</option>
<option>2019</option>
<option>2020</option>
<option>2021</option>
<option>2022</option>
<option>2023</option>
<option>2024</option>
<option>2025</option>
</select>
</p>
<p>
<label for="cardsortcode">Sort Code (if applicable) </label>
<input name="cardsortcode" type="text" id="cardsortcode" tabindex="8" value="XX-XX-XX" size="32" maxlength="8" /><b id="cardsortcodeerror">&nbsp;</b>
</p>
<p>
<label for="cardsecurecode">Secure Code*</label>
<input name="cardsecurecode" type="text" id="cardsecurecode" tabindex="9" value="XXX" size="32" maxlength="3" /><b id="cardsecurecodeerror">&nbsp;</b>
</p>
<p><input name="submit" type="submit" id="submit" value="Next" /></p>
</form>
</body>

Reply With Quote
  #2  
Old January 8th, 2012, 09:10 PM
KallumTanton KallumTanton is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 4 KallumTanton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 13 sec
Reputation Power: 0
Edit

--EDIT--
I've just realised, the second form doesn't actually display the errors at all, all it does is lock out the selection menu (seems to remove all value from it) until the page is reloaded. And here's me thinking I know how to code

Reply With Quote
  #3  
Old January 10th, 2012, 12:08 PM
KallumTanton KallumTanton is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 4 KallumTanton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 13 sec
Reputation Power: 0
Ahh, figured out the problem with the first form;
I told to form to run the validatePaypal() script onsubmit, but I DIDN'T tell it to return it's output, ie onsubmit="return validatePaypal" Explains why I got the errors but it ignored the output.

Unfortunately, the second form and scripting (validateCard) is still confusing the hell outta me, even adding 'return' to the onsubmit it continues to send the form, definitely a scripting error here.

Reply With Quote
  #4  
Old January 11th, 2012, 11:50 AM
KallumTanton KallumTanton is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 4 KallumTanton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 13 sec
Reputation Power: 0
Fixed the second one too. Looks like it was just the placement of some of the error message placeholders. For example, the card type error message was set to appear in the middle of the drop down element, which just broke it.

Well, seem as noone actually provided any help I guess that noone has had this problem or thought it wasn't worth their time of looking at. Anyway, thanks anyway, hope this finds it's way to being somewhat helpful to someone in the future.

Reply With Quote
  #5  
Old March 7th, 2012, 01:51 AM
MariluChester MariluChester is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2012
Posts: 8 MariluChester User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 m 20 sec
Reputation Power: 0
figured out the problem with the first form


Reply With Quote
  #6  
Old March 7th, 2012, 10:57 PM
jaldjoelajeoaj jaldjoelajeoaj is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 4 jaldjoelajeoaj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 17 sec
Reputation Power: 0
Fixed the second one too. Looks like it was just the placement of some of the error message placeholders. For example, the card type error message was set to appear in the middle of the drop down element, which just broke it.URL
URL

Reply With Quote
  #7  
Old March 14th, 2013, 03:14 AM
rcmvashd rcmvashd is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 4 rcmvashd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 13 sec
Reputation Power: 0
Explains why I got the errors but it ignored the output.URLURLURLURLURLURL

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Need Help Debugging Script/Error in Script - Form Validation Error - Form Seemingly Ignores Return Value


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 - 2017, Jelsoft Enterprises Ltd.

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