Testing for the existence of variables in JavaScript
Posted: Wed Sep 03, 2003 6:22 am
Hi,
JavaScript problem:
I'm currently building an e-commerce site. I need to 'force' my customers to read my terms and conditions before parting with their hard earned cash through our WorldPay connection. I am using a checkbox and 'onsubmit' in the body tag to check that they have clicked on a 'I understand I am handing over all my rights etc.' checkbox. This works fine - almost! Some browsers are giving errors and here's the reason:
The status of the checkbox is being checked (i.e. is it clicked?), but to stop error messages that some browsers are giving me, I would like to add some extra JS to test for the 'existence' of the checkbox field first. So the pseudo-code would look like this:
if exists(checkbox-field){
if checkbox field has been clicked{
Allow the form post to be completed
{
}
I can check whether the checkbox has been clicked but not whether it exists in the first place. (I know this sounds a bit odd, but I have reasons which I will expand on if requested, it will just take even MORE verbosity than I am normally guilty of!)
Many thanks,
Mike B
JavaScript problem:
I'm currently building an e-commerce site. I need to 'force' my customers to read my terms and conditions before parting with their hard earned cash through our WorldPay connection. I am using a checkbox and 'onsubmit' in the body tag to check that they have clicked on a 'I understand I am handing over all my rights etc.' checkbox. This works fine - almost! Some browsers are giving errors and here's the reason:
The status of the checkbox is being checked (i.e. is it clicked?), but to stop error messages that some browsers are giving me, I would like to add some extra JS to test for the 'existence' of the checkbox field first. So the pseudo-code would look like this:
if exists(checkbox-field){
if checkbox field has been clicked{
Allow the form post to be completed
{
}
I can check whether the checkbox has been clicked but not whether it exists in the first place. (I know this sounds a bit odd, but I have reasons which I will expand on if requested, it will just take even MORE verbosity than I am normally guilty of!)
Many thanks,
Mike B