Here’s a snippet of my code:
onclick : function(){ // default button function
form = new Object();
field = new Object();
form.vald = 0;
field.first = $('input[name$="sf_name"]');
field.last = $('input[name$="sf_last"]');
field.title = $('input[name$="sf_title"]');
field.company = $('input[name$="sf_company"]');
field.email = $('input[name$="sf_email"]');
field.phone = $('input[name$="sf_phone"]');
field.key = $('input[name$="sf_key"]');
fields = new Array();
if (!field.first.val()) {
fields.push("First Name");
}
if (!field.last.val()) {
fields.push("Last Name")
}
if (!field.title.val()) {
fields.push("Title")
}
if (!field.company.val()) {
fields.push("Company")
}
if (!field.email.val()) {
fields.push("Email")
}
if (!field.phone.val()) {
fields.push("Phone")
}
console.log(fields);
if (form.valid == 0) {
window.location = "<?php bloginfo('url'); ?>/download?viewkey="+field.key.val();
} else {
alert('Please correct the following fields before continuing: ');
//$('#form_487940 input').css("box-shadow", "inset #BBB 0px 0px 5px");
}
As you can see any invalid fields gets pushed into an array, I need to show all the invalid fields in an alert box after ‘Please correct the following fields before continuing:’.
Any help would be appreciated, maybe I could achieve the same result doing it a different way.
use
array.joinlike so:would output a comma-separated list like