Link to home
Start Free TrialLog in
Avatar of Enflow
EnflowFlag for United States of America

asked on

JavaScript Form Validation Tweaks

Script Tweaks on Existing Code

ONE) Check to see there are TWO Names in Contact.value field (with a space in between)

TWO) If AMEX is CCard choice then USER NEEDS 4 numbers in CVV field... existing code that checks this does not work

see attached word doc... Yellow highlighted code needs tweaking...

thanks... Cj
function openMod() {
    //var x = document.getElementById("mySessID").value;
    //alert(x);
    var CardNumber = document.getElementById('<%= CardNumber.ClientID %>');
    var ExMonth = document.getElementById('<%= ExpMonth.ClientID %>');
    var ExYear = document.getElementById('<%= ExpYear.ClientID %>');
    var Address = document.getElementById('<%= address.ClientID %>');
    var State = document.getElementById('<%= state.ClientID %>');
    var Zip = document.getElementById('<%= zip.ClientID %>');
    var company = document.getElementById('<%= company.ClientID %>');
    var contact = document.getElementById('<%= contact.ClientID %>');
    var telephone = document.getElementById('<%= telephone.ClientID %>');
    var city = document.getElementById('<%= city.ClientID %>');
    var fax = document.getElementById('<%= fax.ClientID %>');
    var email = document.getElementById('<%= email.ClientID %>');
    var howhear = document.getElementById('<%= howhear.ClientID %>');
    var CardType = document.getElementById('<%= CardType.ClientID %>');
    var CVV = document.getElementById('<%= CVV.ClientID %>');
    if (company.value == '') {
        alert('Please Enter Your Company Name');
        company.focus();
        return false;
    }
    if (contact.value == '') {
        alert(Please Enter Your FULL Credit Card Signature Name - Both FIRST Name & LAST Name’);
        contact.focus();
        return false;
    }
    if (Address.value == '') {
        alert('Please Enter Your Credit Card Billing Street Address');
        Address.focus();
        return false;
    }
    if (city.value == '') {
        alert('Please Enter Your City');
        city.focus();
        return false;
    }
    if (State.value == '') {
        alert('Please Enter Your State');
        State.focus();
        return false;
    }
    if (Zip.value == '') {
        alert('Please Enter Your Credit Card Billing Zip Code Number');
        Zip.focus();
        return false;
    }
    if (email.value == '') {
        alert('Please Enter Your Email Address Where You Want Us To Send The Data');
        email.focus();
        return false;
    }
    if (telephone.value == '') {
        alert('Please Enter Your Telephone Number');
        telephone.focus();
        return false;
    }
    if (howhear.options[howhear.selectedIndex].text == 'Choose One') {
        alert('Please Select How You Heard About Us - Referral');
        howhear.focus();
        return false;
    }
    if (CardType.options[CardType.selectedIndex].text == 'Choose One') {
        alert('Please Enter Your Credit Card Type');
        howhear.focus();
        return false;
    }
    if (CardNumber.value == '') {
        alert('Please Enter Your Credit Card Number');
        CardNumber.focus();
        return false;
    }
    if (CVV.value == '') {
        alert('Please Enter Your Credit Card CVV Number');
        CVV.focus();
        return false;
    }
    if (CardType.options[CardType.selectedIndex].text == 'AMEX')
        if (CVV.length < '4') {
            alert('Please Enter ALL 4 numbers for an American Express Credit Card CVV Number');
            CVV.focus();
            return false;
        }
    if (ExMonth.options[ExMonth.selectedIndex].text == '??') {
        alert('Please Enter Your Credit Card Expiration Month');
        ExMonth.focus();
        return false;
    }
    if (ExYear.options[ExYear.selectedIndex].text == '??') {
        alert('Please Enter Your Credit Card Expiration Expiration Year');
        ExYear.focus();
        return false;
    }
    var exDate = ExMonth.options[ExMonth.selectedIndex].text + ExYear.options[ExYear.selectedIndex].text;
    $(document).ready(function () {
        $('#basic-modal-content').modal();
    });
    return goToAuthorize(CardNumber.value, exDate, Address.value, State.value, Zip.value);
}

Open in new window

JavaScript-As-Is-Now.doc
SOLUTION
Avatar of Sar1973
Sar1973
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Rob
What sar1973 means is that the single quote is missing from the beginning of your alert message. (Double quotes fine as well)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Enflow

ASKER

Sar1973...  Sorry...
In my attached file i FORGOT to put in the single Apostrophe at the beginning of the Alert text after i edited it after i copy pasted it... but in my LIVE code the single ' is there at both ends where needed and the alert works... that never was the problem... but

but... my question was HOW do i TEST for TWO Names being in one text box with a SPACE... so i know the user has entered their First and Last names...


TAGIT...
From you solution in CVV length test of  ---If(CVV.value.length < 4) {   -  I was able to also note i should have changed my original code from...

 if (CardType.options[CardType.selectedIndex].text == 'AMEX')
        if (CVV.length < '4') {
            alert('Please Enter ALL 4 numbers for an American Express Credit Card CVV Number');
            CVV.focus();
            return false;
        }

and changed it to...

if(CardType.options[CardType.selectedIndex].value == 'American Express')
                  if(CVV.value.length < 4) {
                        alert('Please Enter ALL 4 numbers for an American Express Credit Card CVV Number');
                        CVV.focus();
                        return false;
        }      

which not only incorporated your solution but also changed .text to .value in first if statement and 'AMEX' to American Express which is the correct value... 100 points... thanks...


Gary123...
tried your solution... it looks right but the Javascript function as whole does not work if i incorporate it...

here is your code inline...

 function openMod()
    {  
        //var x = document.getElementById("mySessID").value;
        //alert(x);
        var CardNumber = document.getElementById('<%= CardNumber.ClientID %>');
        var ExMonth = document.getElementById('<%= ExpMonth.ClientID %>');        
        var ExYear = document.getElementById('<%= ExpYear.ClientID %>');
        var Address = document.getElementById('<%= address.ClientID %>');
        var State = document.getElementById('<%= state.ClientID %>');
        var Zip = document.getElementById('<%= zip.ClientID %>');      
        var company = document.getElementById('<%= company.ClientID %>');
        var contact = document.getElementById('<%= contact.ClientID %>');
        var telephone = document.getElementById('<%= telephone.ClientID %>');
        var city = document.getElementById('<%= city.ClientID %>');
        var fax = document.getElementById('<%= fax.ClientID %>');
        var email = document.getElementById('<%= email.ClientID %>');
        var howhear = document.getElementById('<%= howhear.ClientID %>');
        var CardType = document.getElementById('<%= CardType.ClientID %>');            
        var CVV = document.getElementById('<%= CVV.ClientID %>');
            
        if(company.value == '')
        {
            alert('Please Enter Your Company Name');
            company.focus();
            return false;
        }
            
            if (contact.value == '' || contact.value.indexOf(" ")<1)
            {
                  alert('Please Enter Your FULL Credit Card Signature Name - Both FIRST Name & LAST Name’);
                  contact.focus();
                  return false;
        }
            
            if(Address.value == '')
        {
            alert('Please Enter Your Credit Card Billing Street Address');
            Address.focus();
            return false;
        }

etc...

thanks... Cj

CJ
Here
alert('Please Enter Your FULL Credit Card Signature Name - Both FIRST Name & LAST Name’);

You have a different apostrophe at the beginning as compared to the end

My fault, change it to
alert('Please Enter Your FULL Credit Card Signature Name - Both FIRST Name & LAST Name');
Avatar of Enflow

ASKER

Bingo ! - Perfectamundo...

thanks GaryC...  :o)

Okay... Am I able to divide the points like this...

125 points - Gary C123
100 points - Tagit
25 points - Sar1973

CJ
Avatar of Enflow

ASKER

thanks to all..

will be back soon with an Ajax JavaScript problem... CJ...