I was wondering how i can declare a variable outside a function and be able to the variable value within the function.
I tried the code below but it did not work. I thought to declare a global variable you used the "var" keyword. Here is the code i tried:
var firstTry = false;
function checkoutFields(formInfo) {
if ((!formInfo.Surname.value == "") && (!formInfo.Diff_Address.checked) && (firstTry == false)) {
alert(messArray[19]);
var firstTry = true;
}
if (firstTry) {
formInfo.Diff_Address.value = true;
var firstTry = false;
}
}
This always gives firstTry as undefined when the function is activated
I tried the code below but it did not work. I thought to declare a global variable you used the "var" keyword. Here is the code i tried:
var firstTry = false;
function checkoutFields(formInfo) {
if ((!formInfo.Surname.value == "") && (!formInfo.Diff_Address.checked) && (firstTry == false)) {
alert(messArray[19]);
var firstTry = true;
}
if (firstTry) {
formInfo.Diff_Address.value = true;
var firstTry = false;
}
}
This always gives firstTry as undefined when the function is activated