J
Juan Schwartz
onSubmit of form is set to
"check_phone('fax','billing_group_info','Fax Number');
check_errors();" but when submitted it does not actually run the above
in onsubmit. if you put those at the top of the browser(with
javascript: ") or hardcode them into html tags, they work. I know the
return part is outside of the for loop and would conflict with more
than one form, but it's not working with one form so I haven't
addressed that yet. Any help?
arr_validate = new Array();
err_msg = new Array();
function add_validation(func, field, form_name, field_desc) {
arr_validate.push(new Array(func, field, form_name, field_desc));
}
function check_all_validation() {
if (arr_validate.length > 0) {
for ( i in arr_validate ) {
if(typeof(document.getElementsByName(arr_validate
[2]).onsubmit) == "undefined") {
document.getElementsByName(arr_validate[2]).onsubmit =
arr_validate[0] + '(' + '\''+ arr_validate[1] + '\'' + ',' +'\''
+ arr_validate[2] + '\'' + ',' + '\'' + arr_validate[3] + '\'' +
'); ';
} else {
document.getElementsByName(arr_validate[2]).onsubmit =
document.getElementsByName(arr_validate[2]).onsubmit +
arr_validate[0] + '(' + '\''+ arr_validate[1] + '\'' + ',' +'\''
+ arr_validate[2] + '\'' + ',' + '\'' + arr_validate[3] + '\'' +
'); ';
}
}
document.getElementsByName(arr_validate[2]).onsubmit =
document.getElementsByName(arr_validate[2]).onsubmit + 'return
check_errors();';
alert(document.getElementsByName(arr_validate[2]).onsubmit);
}
}
function check_phone(field, form_name, field_desc) {
var phone_no = document.getElementsByName(field)[0].value;
if( !phone_no.match( '/^((1-?)?.?[0-9]{3}.{0,2}[0-9]{3}.?[0-9]{4}.*)?
$/' ) ) {
err_msg.push('Phone number in field "' + field_desc + '" is
invalid');
}
}
function check_zip(field, form_name, field_desc) {
var zip = document.getElementsByName(field)[0].value;
if( !zip.match( '/^\d{5}$/' ) ) {
err_msg.push('Phone number in field "' + field_desc + '" is
invalid');
}
}
function check_errors() {
if (err_msg.length > 0) {
alert('The following errors occurred: \n\n' + err_msg.join('\n\n'));
return false;
} else {
return true;
}
}
"check_phone('fax','billing_group_info','Fax Number');
check_errors();" but when submitted it does not actually run the above
in onsubmit. if you put those at the top of the browser(with
javascript: ") or hardcode them into html tags, they work. I know the
return part is outside of the for loop and would conflict with more
than one form, but it's not working with one form so I haven't
addressed that yet. Any help?
arr_validate = new Array();
err_msg = new Array();
function add_validation(func, field, form_name, field_desc) {
arr_validate.push(new Array(func, field, form_name, field_desc));
}
function check_all_validation() {
if (arr_validate.length > 0) {
for ( i in arr_validate ) {
if(typeof(document.getElementsByName(arr_validate
[2]).onsubmit) == "undefined") {
document.getElementsByName(arr_validate[2]).onsubmit =
arr_validate[0] + '(' + '\''+ arr_validate[1] + '\'' + ',' +'\''
+ arr_validate[2] + '\'' + ',' + '\'' + arr_validate[3] + '\'' +
'); ';
} else {
document.getElementsByName(arr_validate[2]).onsubmit =
document.getElementsByName(arr_validate[2]).onsubmit +
arr_validate[0] + '(' + '\''+ arr_validate[1] + '\'' + ',' +'\''
+ arr_validate[2] + '\'' + ',' + '\'' + arr_validate[3] + '\'' +
'); ';
}
}
document.getElementsByName(arr_validate[2]).onsubmit =
document.getElementsByName(arr_validate[2]).onsubmit + 'return
check_errors();';
alert(document.getElementsByName(arr_validate[2]).onsubmit);
}
}
function check_phone(field, form_name, field_desc) {
var phone_no = document.getElementsByName(field)[0].value;
if( !phone_no.match( '/^((1-?)?.?[0-9]{3}.{0,2}[0-9]{3}.?[0-9]{4}.*)?
$/' ) ) {
err_msg.push('Phone number in field "' + field_desc + '" is
invalid');
}
}
function check_zip(field, form_name, field_desc) {
var zip = document.getElementsByName(field)[0].value;
if( !zip.match( '/^\d{5}$/' ) ) {
err_msg.push('Phone number in field "' + field_desc + '" is
invalid');
}
}
function check_errors() {
if (err_msg.length > 0) {
alert('The following errors occurred: \n\n' + err_msg.join('\n\n'));
return false;
} else {
return true;
}
}