...

View Full Version : function calling a function issue



justincredible
06-05-2007, 04:43 PM
Here are my functions:

function submit_order( form ) {
if (!form.agreed.checked) {
alert( \"". $VM_LANG->_PHPSHOP_AGREE_TO_TOS ."\" );
return false;
}
else {
check_cb2(this.form);
}
}

function check_cb2( form ) {
if (!form.bkwarn.checked) {
alert( \"". $VM_LANG->_PHPSHOP_BK_WARN_CHECK ."\" );
return false;
}
else {
return true;
}
}

Here is where it is getting called:

<input type="submit" onclick="return( submit_order( this.form ) );" class="button_2" name="submit" value="<?php echo $VM_LANG->_PHPSHOP_ORDER_CONFIRM_MNU ?>" />

It is just checking to make sure two checkboxes are checked before the form can be submitted.

If checkbox "agreed" is not checked it will pop up my alert. If I check it the form will submit regardless of whether or not "bkwarn" is checked.

Any ideas?

glenngv
06-05-2007, 04:58 PM
else {
check_cb2(this.form);
return true;
}

justincredible
06-05-2007, 08:37 PM
else {
check_cb2(this.form);
return true;
}

Thanks for the reply.

Unfortunately that works the same way as before. The only checkbox that needs to be checked is "agreed" before the form submits. :(

glenngv
06-05-2007, 08:55 PM
Then don't call check_cb2 function in the "else" block if you don't want to validate "bkwarn" when "agreed" is checked.

When do you really want to validate "bkwarn"?

justincredible
06-05-2007, 09:06 PM
I want both to be validated before the form is submitted.

I should rephrase "The only checkbox that needs to be checked is "agreed" before the form submits" to say that it is only requiring "agreed" to be checked now, but I need them both to be checked.

What I was trying to do was check if agreed is checked. If not, return the alert. If it is checked, see if bkwarn is checked. If not, return the alert. If it is checked, submit the form.

There is probably a better way to do this, this was just the first thing that came to mind. It was originally just checking "agreed" as it was the only checkbox, I have had to add an extra checkbox so I was just trying to add on to the existing javascript.

glenngv
06-05-2007, 09:50 PM
If you need both to be validated, then just return the value of check_cb2.

function submit_order( form ) {
if (!form.agreed.checked) {
alert(". $VM_LANG->_PHPSHOP_AGREE_TO_TOS .");
return false;
}
return check_cb2(this.form);
}

justincredible
06-05-2007, 09:54 PM
Thanks, that does it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum