好的,所以这适用于我尝试过的所有浏览器,但是当我尝试使用Internet Explorer时,它就像我甚至没有CheckForm Action那样。任何帮助都会很棒。这是剧本。
function MM_preloadImages() { //v3.0
var d = document;
if (d.images) {
if (!d.MM_p) d.MM_p = new Array();
var i, j = d.MM_p.length,
a = MM_preloadImages.arguments;
for (i = 0; i < a.length; i++)
if (a[i].indexOf("#") != 0) {
d.MM_p[j] = new Image;
d.MM_p[j++].src = a[i];
}
}
}
function checkForm() {
var errors = "";
if (isEmpty("Name")) {
errors += "- Name missing\n";
}
if (isEmpty("Email")) {
errors += "- Email missing\n";
}
if (isEmpty("Phone")) {
errors += "- Phone missing\n";
}
if (isEmpty("Dateneed")) {
errors += "- Date Needed Missing\n";
}
if (isEmpty("ZipCode")) {
errors += "- Zip code mising\n";
}
if (errors.length != 0) {
errors += "\n";
}
var rad_val = document.form1.LanyardStyle.value;
var quantity = parseInt(document.form1.Quantity2.value);
if (isNaN(quantity)) {
quantity = 0;
}
if (rad_val == 'Polyester' && quantity < 100) {
errors += "- Minimum order for Polyester is 100";
}
else if (rad_val == 'AntiMicro' && quantity < 100) {
errors += "- Minimum order for AntiMicro is 100";
}
else if (rad_val == 'Bamboo' && quantity < 100) {
errors += "- Minimum order for Bamboo is 100";
}
else if (rad_val == 'PET' && quantity < 100) {
errors += "- Minimum order for PET is 100";
}
else if (rad_val == 'Reflective' && quantity < 100) {
errors += "- Minimum order for Reflective is 100";
}
else if (rad_val == 'Dyesub' && quantity < 200) {
errors += "- Minimum order for Dyesub is 200";
}
else if (rad_val == 'Woven' && quantity < 500) {
errors += "- Minimum order for Woven is 500";
}
if (errors.length > 0) {
alert("Information missing or invalid:\n\n" + errors);
return false;
}
return true;
}
function getText(id) {
return document.getElementById(id).value.trim();
}
function isEmpty(id) {
if (getText(id).length == 0) {
return true;
}
return false;
}
答案 0 :(得分:0)
试试这个:
function checkForm() {
var rad = document.form1.LanyardStyle.value,
quantity = parseInt(document.form1.Quantity2.value, 10) || 0,
errors = '',
fields = ['Name', 'Email', 'Phone', 'Dateend', 'ZipCode'],
min = {'Polyester':100, 'AntiMicro':100, 'Bamboo':100, 'PET':100,
'Reflective':100, 'Dyesub':200, 'Woven':500};
for (var i = 0, l = fields.length; i < l; i++) {
if ( isEmpty(fields[i]) ) {
errors += '- ' + fields[i] + ' missing\n';
}
}
if ( quantity < min[rad] ) {
errors += '- Minimum order for ' + rad + ' is ' + min[rad];
}
if ( errors ) {
alert('Information missing or invalid:\n\n' + errors);
return false;
}
return true;
}