This time I want to validate several select boxes on a form. If everything is all right, I want the confirm box pops up. If yes, submit the form; if cancel, do not do anything.
The validation part is working. My code is as follows. But how can I add the confirm box to it, I mean the logic (conditions) to make the code as a whole to work together?
function upd_ele(f){
if ((f.elements["den"].options[0].selected == true) && (f.elements["vis"].options[0].selected == false)){
self.alert("Error:\n\nThe Vision plan can be elected only if you are enrolled in the Dental Plan."
;
f.elements["den"].focus();
return(false);
}
else {
var den_value = "";
var vis_value = "";
for (var i=0; i<thisform.elements["den"].length; i++){
if (thisform.elements["den"].options.selected){
den_value = thisform.elements["den"].options.value;
}
}
for (var i=0; i<thisform.elements["vis"].length; i++){
if (thisform.elements["vis"].options.selected){
vis_value = thisform.elements["vis"].options.value;
}
}
if (den_value.substr(8,3) != vis_value.substr(8,3) && vis_value != ""
{
self.alert("Error:\n\nThe coverage levels of your Dental plan and Vision plan must be same."
;
return(false);
}
}
return(true); /* I want to add confirm box here, the code would be: if (confirm("..."
) {
return(true);
} else {
return(false);
}
}*/
}
How can I add a condition to make both the validation part and confirm box to work together.
Thanks in advance...
-J
The validation part is working. My code is as follows. But how can I add the confirm box to it, I mean the logic (conditions) to make the code as a whole to work together?
function upd_ele(f){
if ((f.elements["den"].options[0].selected == true) && (f.elements["vis"].options[0].selected == false)){
self.alert("Error:\n\nThe Vision plan can be elected only if you are enrolled in the Dental Plan."
f.elements["den"].focus();
return(false);
}
else {
var den_value = "";
var vis_value = "";
for (var i=0; i<thisform.elements["den"].length; i++){
if (thisform.elements["den"].options.selected){
den_value = thisform.elements["den"].options.value;
}
}
for (var i=0; i<thisform.elements["vis"].length; i++){
if (thisform.elements["vis"].options.selected){
vis_value = thisform.elements["vis"].options.value;
}
}
if (den_value.substr(8,3) != vis_value.substr(8,3) && vis_value != ""
self.alert("Error:\n\nThe coverage levels of your Dental plan and Vision plan must be same."
return(false);
}
}
return(true); /* I want to add confirm box here, the code would be: if (confirm("..."
return(true);
} else {
return(false);
}
}*/
}
How can I add a condition to make both the validation part and confirm box to work together.
Thanks in advance...
-J