PDA

View Full Version : Occasional failure of prompt box


Philip M
04-14-2003, 07:38 AM
I have encountered a problem with my on-line order form which is
completely baffling.

When the user moves the focus to the credit card number text box
a prompt message should appear, and the number entered is
then validated (i.e. a valid card number) before being put
in the CardNumber textbox. And once entered a second
entry is blocked.

This works almost all the time, but a few cases customers have
been able to enter invalid card numbers directly into the text box,
that is the prompt box does not appear. This is not because
they have disabled JavaScript, as other sections of the form
work OK. Stangely nearly all of these cases have involved
customers from outside the UK - in USA, Canada, New Zealand,
Belgium, but I cannot believe that is relevant.

The HTML code is:-

<tr> <td align="right"><font face="Arial" size="3"><em><b>Card
Number </b></em></td>
<td><input type="text" size="30" name="CardNumber" onfocus="doCCStuff(this.form.CardNumber)"></font></td>
</tr>

The relevant script is:-

var cardnum="";
var blur_reset = true;

function doCCStuff(crcardnumber) {
if (blur_reset) {
cardnum = getCCNum();
var strippednumber = strip(cardnum);
while (cardnum && (!isCreditCard(strippednumber))) {
alert ('The credit card number you entered could not be '
+ 'validated.\nPlease check the number and try again.');
cardnum = getCCNum();
strippednumber = strip(cardnum);
}
if (cardnum) {crcardnumber.value = tpyrcne(cardnum)}
blur_form(crcardnumber);
}
return (false);
}

function blur_form(form_element) {
form_element.blur();
blur_reset = false;
setTimeout ("blur_reset=true",200);
}

function getCCNum() {
if (document.forms[0].CardNumber.value !="") {
alert ("You have already entered your card number which \nhas been validated, scrambled and encrypted.");
return false; // no re-entry if a valid card number already entered
}
msg = 'Please enter your credit card number here - then click OK. '
+ ' It will be validated and then put into the credit card field of the form after it has been encrypted.';
return prompt (msg,cardnum);
}


As I see it the problem must be either that "onfocus" is not supported by
the browsers (but they are using IE), or for some reason the variable
"blur_reset" evaluates to "false". So the function getCCNum() is not called.

A long shot - could </font> be in the wrong place? I am unable to test
modifications as the form works perfectly for me (IE5.5) both off and on line,
and as I say works for most of my customers.

If anyone wants to see the whole thing the URL is
www.ogauge.co.uk/ordfrm.html

As I say, I am baffled! Any advice will be much appreciated.

HairyTeeth
04-14-2003, 09:11 AM
Using IE 5.01 (australia): no prompt

Philip M
04-14-2003, 10:30 AM
Many thanks, Hairyteeth!

Any ideas why not, but I THINK the problem may be in IE5.01.

HairyTeeth
04-14-2003, 10:40 AM
encrytion perhaps?

Philip M
04-14-2003, 11:44 AM
I should say that the whole thing works fine in IE5.5, Netscape 4.7 and Opera 5.

The problem is not to do with the encryptation - the user does not get that far as no prompt box appears.

As I say, I have some evidence that the problem lies in IE 5.01. But it baffles me what it is!

I have made some alterations (but with only faint hope that they will make any difference!)

Please could Hairyteeth or someone with access to IE 5.01 test it for me again - when the focus is placed on the credit card box does the prompt box appear?

Philip M
04-14-2003, 09:47 PM
Oh noble Beetle! Oh hirsute Hairytooth! Vouchsafe unto us why this form prompt box works in IE5.5, Netscape 4.7, Opera 5 but NOT in IE 5.01. Hear our prayer and enlighten our ignorance!

beetle
04-14-2003, 10:30 PM
Internet Explor(d)er 5.0 has some internal regular expression parsing problems (as does IE 5.something Mac) that generates "unexpected quantifier" errors. I found a knowledge-base entry for this on MSDN like a year ago while working on fValidate. I can't find it at the moment, but I'll keep looking and post it when I find it.

Long story short, the prompt probably shows, the data being entered isn't correctly validated cause the regex is breaking.

P.S.
You're using a regex, right? (I didn't look)

Philip M
04-15-2003, 07:23 AM
Oh most knowledgeable and honoured Beetle! Thank you for your response. But in fact there are no regex's involved and the problem is that the prompt box does not show in IE 5.01. In other words, the validation section is never reached, although there are no syntax errors in the script.

I have changed

onfocus="doCCStuff(this.form.CardNumber)"

to onfocus="doCCStuff(this)"

This makes no difference to the action in IE5.5 etc. I don't have the expertise to know exactly what the difference between these expressions is.

glenngv
04-15-2003, 08:32 AM
try putting an alert at the start of the doCCStuff() function. maybe the blur_reset variable is false.

function doCCStuff(crcardnumber) {
alert(blur_reset);
if (blur_reset) {
...

and what is blur_form() function for?
when do you call it. in it you reset blur_reset to false

Philip M
04-15-2003, 02:45 PM
Hi Glenngv,

Thanks for your input.

The problem only arises in IE 5.05 which I do not have. It all works perfectly in IE 5.5 and blur_reset is true so the prompt box appears.

The blur_reset is a function simply to remove the focus from the textbox after the card number has been entered. Otherwise the alert when a second entry is attempted is triggered. You will see that it is reset to true after 200 millsecond

Philip M
04-15-2003, 06:39 PM
Eureka! I think I have solved this very obscure problem, and I am posting the solution for the benefit of all.

The problem is that the form HTML was as follows:-

<tr>
<td align="right"><font face="Arial" size="3"><em><b>Cardholder
Name </b></em></td>
<td><input type="text" size="30" maxlength="34" name="CardHolderName" ONBLUR="changeCase(this)"></font></td>
</tr>
<tr>
<td align="right"><font face="Arial" size="3"><em><b>Card
Number </b></em></td>
<td><input type="text" size="30" name="CardNumber" ONFOCUS="doCCStuff(this)"></font></td>
</tr>

So in some way the ONBLUR event handler screwed up the ONFOCUS event handler in the next textbox, resulting in the script doCCStuff() not being called.

The solution is simple - alter ONBLUR to ONCHANGE.

I have encountered a variant of this problem before - two ONBLURS in succession can cause problems as well.

The odd thing is that the problem only manifests itself in IE 5.01, and NOT in IE 5.5, Netscape 4.7 or Opera 5.

Thanks to those people who kindly responded.

beetle
04-15-2003, 06:51 PM
Ya, using lots of focus control in forms can cause some funky sh*t. Glad you got to the bottom of it, Philip.