Validating PayPal Form on iPhone

29 views Asked by At

Paypal add to cart button form ignores the "return false" and submits. This script works on a desktop browser but it won't work on my iPhone. The input turns red, but the form still submits. It can be tested at membership form

$('input[name="submit"]').click(function() {
$(':input').each(function(input) {
    if($(this).attr('required')) {
        var required = $(this);
        if(required.attr('pattern')) {
            var patt =  new RegExp(required.attr('pattern'),"i");
            if( !patt.test( required.val() ) ) {
                required.css('background-color','#f2dede');
                return false;
            }
        }
        else {
            if(required.val() == '') {
                required.css('background-color','#f2dede');
                return false;
            }
        }
    }
});
1

There are 1 answers

0
Elliott On

By placing an "e" in the function(e) for the event, and then use e.preventDefault() I was able to keep the form from submitting.

$('input[name="submit"]').click(function(e) {
$(':input').each(function(input) {
    if($(this).attr('required')) {
        var required = $(this);
        if(required.attr('pattern')) {
            required.css('background-color','inherit');
            var patt =  new RegExp(required.attr('pattern'),"i");
            if( !patt.test( required.val() ) ) {
                required.css('background-color','#f2dede');
                e.preventDefault();
                window.scroll(0,144);
            }
        }
        else {
            if(required.val() == '' || required.val() == null) {
                required.css('background-color','#f2dede');
                e.preventDefault();
                window.scroll(0,144);
            }
        }
    }
});