سؤال

I am using credit card validation in my cartridge project to validate the card type and card number.Everything is working fine, but whenever I got the validation error in alert box and when I click OK it doesn't stop on that page but refer me to the next page,Thus I am getting an error or not my order is got placed.

Here is my code.

<input type="submit" class="btn btn-large btn-primary" onClick="cardchk();" value="{% trans "Next" %}">

    function cardchk()
    {

        var card_typ=$("input[name='card_type']:checked")[0].value;
        //alert(card_typ);

        if(card_typ=='Visa')
        {
            var  cardname = 'Visa';
        }
        else
        {
            var  cardname = 'MasterCard';
        }
        //alert(cardname);
        var cardnumber = document.getElementById('id_card_number').value;
        if(!checkCreditCard (cardnumber, cardname)){
            alert(ccErrors[ccErrorNo]);
            return false;
        }

    }

However I have returned false in my function but on getting error it refer me to the confirmation page but I want as normally validation do to stop processing the request whenever I got the error

Thanks !

هل كانت مفيدة؟

المحلول

you need

onClick="return cardchk();"

not just

onClick="cardchk();"

nb. I don't see here that you are using jquery validate

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top