I'm working on an order form.
One of the fields is a dropdown list for Payment Type and the choices are either CreditCard or Check. The next box is for the CreditCard Number and Exp Date.
What I want to do is when the CC Number field loses focus (onBlur) I want to do a check that says IF Payment Type = Credit Card and CC Num is Blank, pop up an alert saying you have to enter a CC Number.
This part works fine.
However, I also thought that what if the person picked CreditCard by mistake, tabbed into the CC Number field, and wanted to go back to Payment Type and change it to Check. The above example wouldn't let them go back and change their choice until they entered something into the CC Num field.
So I thought if there's a way I can see when the CC Num field Blurs, if the PaymentType field regained the focus, then it was OK, and it wouldn't do the check to see if the CC Num field was empty.
I wasn't sure how to do this but I found another post that suggested putting: onfocus="this.hasFocus=true" onblur="this.hasFocus=false" on the Payment Type and I could do a check and if the payment choice box had focus it would skip the rest but it doesn't work.
Here's the current code. The "alert("Type Focus") box (just for testing) never fires
function checkCCNull()
{
if (document.FrontPage_Form1.Payment_Type.options[document.FrontPage_Form1.Payment_Type.options.selectedIndex].value == "Credit_Card")
{
if (document.FrontPage_Form1.Payment_Type.hasFocus == "true")
{
alert("Type Focus")
}
else
{
if (document.FrontPage_Form1.CC_Num.value == "")
{
alert("Please input a Credit Card number to pay with aCredit Card.")
document.FrontPage_Form1.CC_Num.focus()
}
}
}
}
I could do the check in the onSubmit if this way won't work but that would lead to a couple other issues.
I sure hope all that makes sense.
One of the fields is a dropdown list for Payment Type and the choices are either CreditCard or Check. The next box is for the CreditCard Number and Exp Date.
What I want to do is when the CC Number field loses focus (onBlur) I want to do a check that says IF Payment Type = Credit Card and CC Num is Blank, pop up an alert saying you have to enter a CC Number.
This part works fine.
However, I also thought that what if the person picked CreditCard by mistake, tabbed into the CC Number field, and wanted to go back to Payment Type and change it to Check. The above example wouldn't let them go back and change their choice until they entered something into the CC Num field.
So I thought if there's a way I can see when the CC Num field Blurs, if the PaymentType field regained the focus, then it was OK, and it wouldn't do the check to see if the CC Num field was empty.
I wasn't sure how to do this but I found another post that suggested putting: onfocus="this.hasFocus=true" onblur="this.hasFocus=false" on the Payment Type and I could do a check and if the payment choice box had focus it would skip the rest but it doesn't work.
Here's the current code. The "alert("Type Focus") box (just for testing) never fires
function checkCCNull()
{
if (document.FrontPage_Form1.Payment_Type.options[document.FrontPage_Form1.Payment_Type.options.selectedIndex].value == "Credit_Card")
{
if (document.FrontPage_Form1.Payment_Type.hasFocus == "true")
{
alert("Type Focus")
}
else
{
if (document.FrontPage_Form1.CC_Num.value == "")
{
alert("Please input a Credit Card number to pay with aCredit Card.")
document.FrontPage_Form1.CC_Num.focus()
}
}
}
}
I could do the check in the onSubmit if this way won't work but that would lead to a couple other issues.
I sure hope all that makes sense.