Credit card java script file will not validate card number on form

Hello,

I am calling a java script function to validate a card number but it will not validate.
All of the other fields will validate or throw an error except for the credit card number field.
The code to validate the card is below.  I have attached the html and other js files in text format to this question.  Thanks for the help

    // Validate that the Credit Card :
    if (checkCreditCard(cardnumber, cardname)) {
    	removeErrorMessage('cardnumber');
    } else {
    	addErrorMessage('cardnumber', 'Credit Card Number is not valid.');
    	error = true;
    }

Open in new window

popcorn-HTML.txt
popcorn-JS.txt
creditcard-JS.txt
popcorn-CSS.txt
LVL 1
capturetheflagAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michel PlungjanIT ExpertCommented:
Please create a jsfiddle.net with only the pertinent issue

Thanks
0
Sar1973Commented:
Can you provide further details on the credit card field? (i.e. length, characters allowed, etc.)
0
Robert SchuttSoftware EngineerCommented:
There's a number of problems but the one that may be stopping your code from doing anything at all seems to me that you pass html objects instead of strings to the function, try:
if (checkCreditCard(cardnumber.value, cardname.value)) {

Open in new window

0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Robert SchuttSoftware EngineerCommented:
BTW: you may need something other than .value for cardname, also "mc" != "mastercard".
0
Robert SchuttSoftware EngineerCommented:
For the radio value I used this function:
function getRadioValue(f, r) {
 for (var c = 0; c < f[r].length; c++) {
  if (f[r][c].checked) {
   return f[r][c].value;
  }
 }
 return '';
}

Open in new window

Then to call your function use for example:
if (checkCreditCard(cardnumber.value, getRadioValue(cardnumber.form, 'cardname'))) {

Open in new window

I tested it but there's some js files missing, so I just added some stubs to be able to test... Have a look at it here if you want, you can see some other changes I made like not using window.onload when you have U.addEvent(). In the html I changed the id's of the radio's (should be unique) and the value of 'mc' (and fixed a typo, a missing ">").
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Just to make it easy on yourself, I would perhaps just make sure the info for the credit card on your form is a number.  No need to go through all of this as the actual number will be verified when you submit it to the gateway/processor.

One of the problems with this code is you will have to keep watching for updates.

Author:     John Gardner
Date:       1st November 2003
Updated:    26th Feb. 2005      Additional cards added by request
Updated:    27th Nov. 2006      Additional cards added from Wikipedia
Updated:    18th Jan. 2008      Additional cards added from Wikipedia
Updated:    26th Nov. 2008      Maestro cards extended
Updated:    19th Jun. 2009      Laser cards extended from Wikipedia
Updated:    11th Sep. 2010      Typos removed from Diners and Solo definitions (thanks to Noe Leon)

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sar1973Commented:
In the getRadioValue function, try first to replace the '' value assigned to the unchecked case with Null or better to another conventional flag value that may avoid trouble in passing it as a string or value in other functions.
0
capturetheflagAuthor Commented:
Thanks for the help.
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
capturetheflag, thanks for the points.  There is a diverse group of answers here.  Did you come up with a good answer for this or did you just want to close it out?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.