Click to See Complete Forum and Search --> : If statement


dcjones
01-29-2003, 02:47 PM
Hi all

Simple one I think

SCRIPT

if (document.mail.VATnumber.value <1 || document.mail.VATNO.checked==false){
alert("You answered yes to VAT registration, please enter your VAT company registration No.");
return false;
}

When I run this script with VATnumber less than 1 and VATNO un-checked why does the statement return false and display the error message.


Regards

Dereck

gil davis
01-29-2003, 03:23 PM
If document.mail.VATnumber.value is a text field, then it is a string. You cannot correctly compare strings with an integer. You have to convert the string to a number. One way is:

Number(document.mail.VATnumber.value)

dcjones
01-29-2003, 03:42 PM
Hi

and thanks for your reply.

Di I do it this way

Number(document.mail.VATnumber.value)
if (document.mail.VATnumber.value <1 || document.mail.VATNO.checked==false){
alert("You answered yes to VAT registration, please enter your VAT company registration No.");
return false;
}

OR this way

if Number(document.mail.VATnumber.value <1 || document.mail.VATNO.checked==false){
alert("You answered yes to VAT registration, please enter your VAT company registration No.");
return false;


Thanks for your help with this


Regards


Dereck

Charles
01-29-2003, 04:17 PM
Neither,

if (Number(document.mail.VATnumber.value) <1 || document.mail.VATNO.checked==false){
alert("You answered yes to VAT registration, please enter your VAT company registration No.");
return false;
}

dcjones
01-29-2003, 04:30 PM
Hi Charles

I tried your reply

if (Number(document.mail.VATnumber.value) <1 || document.mail.VATNO.checked==false){
alert("You answered yes to VAT registration, please enter your VAT company registration No.");
return false;
}

But

If I select radio button VATNO it returns the error message
If I select radio button VATYES it retrun the error message

All I am trying to do is if VATYES is selected and there is not VATnumber entered the error message should display.

If VATNO is selected then no error message.


Any ideas


Thanks in advance

Dereck