What I want to accomplish is to validate the entry for name, email and phone. If they look OK, I allow advancing to the next entry field by using enter/return or the default tab. The user may as well use the mouse.
If I have a pair user/email or user/phone, I try to bring from a database whatever other elements are available, among them past orders in ddord. This is shown only if it has something; when is created is hidden. addO is irrelevant here.
The trick used is to move the focus to ddord and let onBlur do the real work (including moving the focus to the real destination).
Now, the problem: I put something in the first field (name), press enter, and nothing happens.
If I add an alert(charCode); in phnA() before the if, all works well. Why is this happening and how to solve my problem?
i took a quick second to try and understand how this works. one of the problems i ran into is ambiguity. i can't easily determine what "cst" is supposed to represent (for one example). is it what you expect to be the "email" field? is it some phone field?
i don't want to have to reverse engineer someone's work to troubleshoot it when they're able to directly disambiguate the relationships in the code.
onLoad the focus moves automatically on cst, which is customer's name. This is not shown here.
After typing the name, the user should advance to the next field, by pressing enter, return, tab, or with the mouse. tab's role is built in, so there is no special treatment, the other two keys are recognized by phnA().
With tab the next field is eml (email address), with mouse click depends on user's will. With enter and return the next field is artificially set on ddord, which is hidden at this point.
Checking that the field is not left empty is done onBlur by cstC(). Also, here is where the definitive decision regarding the new focus is taken.
In cstC() is considered the possibility that the user came back in the cst field after filling some other fields. If this is the case, there is an attempt to bring from database whatever is known about the customer. For that to happen, I need a pair cst+phn (phone number) or cst+eml. If I succeed retrieving something from DB, ddord becomes visible, and existing order numbers are placed there (other fields, not mentioned, are activated too). Focus goes next on ddord. Otherwise, focus is moved to the next field, which is eml.
So, that's the general pattern:
- input fields value
- onBlur() check validity and attempt data retrieval from DB, also decide where to focus next (next natural field, or ddord). If validity test fails, go back on the current field
- to implement return and enter I use phnA()
The "natural" succession of fields is cst, eml, phn, o1
This sequence may be broken if data is brought from DB, in which case the focus moves at ddord. If there is selected an existing order for review (from ddord), bring() fills the relevant fields, then moves focus as instructed. If it is a new order, the natural succession resumes.
it works if you put an alert in there because when you clear the alert, cstC() is called as the result of onblur (put an alert in cstc there to see what i mean)
i would speculate that the reason
isn't working is because the target element is hidden... how is it supposed to focus to a hidden element? i speculate that the script "stalls" in some way or basically quits at this point. it can't continue because it can't set focus to the hidden element, maybe? as a side effect of doing an alert, triggering "onblur" seems to "wake the script back up". i dont know, im guessing. but when i removed the visibility (or if you change the hidden element's style before you focus), everything works as expected.
Last edited by TooCrooked; 03-04-2012 at 08:42 PM..