meohmy
meohmy

Reputation: 141

Javascript error seemingly only in IE8

The following code keeps throwing back an error in IE8 (only)

Despite all fields being filled in the alert always comes up. Is this a known issue?

if(errors == 0) {
            return true;
        } else {
            alert("Please complete all (*) marked fields");
            return false;
        }

Full Code:

$(function(){
    $("#d2b").click(function(){

        $("#first_name").val($("#bill_fname").val());
        $("#last_name").val($("#bill_lname").val());
        $("#del_address_1").val($("#bill_address_1").val());
        $("#del_address_2").val($("#bill_address_2").val());
        $("#del_city").val($("#bill_city").val());
        $("#del_county").val($("#bill_county").val());
        $("#del_postcode").val($("#bill_postcode").val());

        return false;
    });

    $("#gpn").submit(function(){

        errors = 0;

        $("#gpn input[type='text']").each(function(){
            var nm = $(this).attr('name');

            if(nm == 'bill_address_2' || nm == 'del_address_2' || nm == 'groupon_barcode') {
                ;
            } else {

                if($(this).attr('name') == 'code') {
                    var gpncode = $(this).val();

                    if(gpncode.length != 10) {
                        errors++;
                        alert("Uh Oh");
                        return;
                    }

                    var str = gpncode;

                    var patt=/[0-9A-Za-z]{10}/g;

                    var result=patt.test(str);

                    if(!result) {
                        errors++;
                        alert("this should be longer");
                    }

                    return;
                }

                if($(this).val() == '') {
                    errors++;
                }
            }

        });

        if(errors == 0) {
            return true;
        } else {
            alert("Please complete all (*) marked fields");
            return false;
        }
    });
});

Upvotes: 2

Views: 363

Answers (1)

doogle
doogle

Reputation: 3406

The code doesn't show errors actually being declared anywhere. Either you are not posting the full code or you are trying to use implicit declaration. The latter is not recommended, try declaring your errors variable like:

var errors = 0;

Upvotes: 1

Related Questions