2

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;
        }
    });
});
2
  • if you are comparing errors to a number try errors === 0 Commented Jan 31, 2012 at 15:35
  • posted the edit above ;) thanks guys Commented Jan 31, 2012 at 15:51

1 Answer 1

1

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;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.