Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Another problem of Confirm box

Status
Not open for further replies.

jianhua

Programmer
Jun 22, 2001
55
US
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[&quot;den&quot;].length; i++){
if (thisform.elements[&quot;den&quot;].options.selected){
den_value = thisform.elements[&quot;den&quot;].options.value;
}
}
for (var i=0; i<thisform.elements[&quot;vis&quot;].length; i++){
if (thisform.elements[&quot;vis&quot;].options.selected){
vis_value = thisform.elements[&quot;vis&quot;].options.value;
}
}
if (den_value.substr(8,3) != vis_value.substr(8,3) && vis_value != &quot;&quot;) {
self.alert(&quot;Error:\n\nThe coverage levels of your Dental plan and Vision plan must be same.&quot;);
return(false);
}
}
return(true); /* I want to add confirm box here, the code would be: if (confirm(&quot;...&quot;)) {
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
 
Code:
function upd_ele(f){
	if ((f.elements[&quot;den&quot;].options[0].selected == true) && (f.elements[&quot;vis&quot;].options[0].selected == false)){
	    self.alert(&quot;Error:\n\nThe Vision plan can be elected only if you are enrolled in the Dental Plan.&quot;);
	    f.elements[&quot;den&quot;].focus();
	    return(false);
	}
	else {
		var den_value = &quot;&quot;;
		var vis_value = &quot;&quot;;
		for (var i=0; i<thisform.elements[&quot;den&quot;].length; i++){
			if (thisform.elements[&quot;den&quot;].options.selected){
				den_value = thisform.elements[&quot;den&quot;].options.value;
			}
		}
		for (var i=0; i<thisform.elements[&quot;vis&quot;].length; i++){
			if (thisform.elements[&quot;vis&quot;].options.selected){
				vis_value = thisform.elements[&quot;vis&quot;].options.value;
			}
		}
		if (den_value.substr(8,3) != vis_value.substr(8,3) && vis_value != &quot;&quot;) {
			self.alert(&quot;Error:\n\nThe coverage levels of your Dental plan and Vision plan must be same.&quot;);
			return(false);
		}
	}
	confirmed = confirm(&quot;Are you sure?&quot;)
	if(confirmed){
		return(true); 
	}
	else{
		return(false);
	}
}
-- Just trying to help...
[wolf]<--- This is a wolf? We need a new icon.......
mikewolf@tst-us.com
 
It does not work. Neither the form is validated, nor does the confirm box pop up. But the database is updated...
 
You said the validation was working... all I added was:
confirmed = confirm(&quot;Are you sure?&quot;)
if(confirmed){
return(true);
}
else{
return(false);
}
-- Just trying to help...
[wolf]<--- This is a wolf? We need a new icon.......
mikewolf@tst-us.com
 
Comment out this, the validation is working; Add this, both the validation and confirm box are not working...
 
after &quot;confirmed = confirm(&quot;Are you sure?&quot;)&quot;
add an alert to see what is stored in confirmed:
confirmed = confirm(&quot;Are you sure?&quot;)
alert (confirmed)
if(confirmed){
alert (&quot;this returned true&quot;)
return(true);
}
else{
alert (&quot;this returned false&quot;)
return(false);
}



-- Just trying to help...
[wolf]<--- This is a wolf? We need a new icon.......
mikewolf@tst-us.com
 
alert box does not pop up, so cannot see what is stored in confirmed. it seems to skip all these...
 
but if you comment this out, the code is working correctly? If that is the case, try just adding
confirmed = confirm(&quot;Are you sure?&quot;) and nothing else. See if you get the confirmation box. Are if..else statements nested correctly above? Can you post what you have again (sorry)... -- Just trying to help...
[wolf]<--- This is a wolf? We need a new icon.......
mikewolf@tst-us.com
 
I don't know why it doesn't fire the confirm box, it seems to me it needs a condition to start the confirm box, so i have changed my code to: (it's working this way)

function upd_eleOnsubmit(thisform){
var err1 = false;
var err2 = false;

if ((thisform.elements[&quot;den&quot;].options[0].selected == true) && (thisform.elements[&quot;vis&quot;].options[0].selected == false)){
err1 = true;
}
else {
var den_value = &quot;&quot;;
var vis_value = &quot;&quot;;
for (var i=0; i<thisform.elements[&quot;den&quot;].length; i++){
if (thisform.elements[&quot;den&quot;].options.selected){
den_value = thisform.elements[&quot;den&quot;].options.value;
}
}
for (var i=0; i<thisform.elements[&quot;vis&quot;].length; i++){
if (thisform.elements[&quot;vis&quot;].options.selected){
vis_value = thisform.elements[&quot;vis&quot;].options.value;
}
}
if (den_value.substr(8,3) != vis_value.substr(8,3) && vis_value != &quot;&quot;) {
err2 = true;
}
} //above is the validation

if (err1 == true){
self.alert(&quot;Error:\n\nThe Vision plan can be elected only if you are enrolled in the Dental Plan.&quot;);
thisform.elements[&quot;den&quot;].focus();
return(false);
}
else if (err2 == true){
self.alert(&quot;Error:\n\nThe coverage levels of your Dental plan and Vision plan must be same.&quot;);
return(false);
}
else {
if (confirm(&quot;By changing your enrollment form, your prior form will not be processed. You must click the Accept button after you have completed all changes to submit your form.&quot;)){
return(true);
}
else {
return(false);
}
}
}

Thanks anyway!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top