View Full Version : Challenge Task Answer this
ksridhar69
07-19-2002, 03:12 PM
There are about 300 text boxes on the page. But user will change the values in only 2 text boxes many times. Is there a way to use function or control keys to focus into these boxes?
<input type="text" name="c1" size="15" maxlength="50">
<input type="text" name="a1" size="15" maxlength="50">
And after hitting tab from the above text box, Is there a way to focus in to last text box. Say user left from this text box
<input type="text" name="z1" size="15" maxlength="50">
mordred
07-19-2002, 03:37 PM
Quote from the "must read"-post:
1) Type in a subject that summarizes your question!- The fastest way to turn off other members wanting to help you is to type an incomplete or silly subject for your post. Examples of poor subject titles include:
- "Help!"
- "I'm a newbie...please!"
- "Is this possible using JavaScript?"
- "loops"
- "Urgent...deadline tomorrow!"
- "A challenge for you JavaScript masters"
The above subjects either have absolutely nothing to do with the question itself, or are grossly incomplete (ie: "loops"). When asking for help, enter a subject that summarizes your question, period! Don't use silly, incomplete, or "bait" subjects.
Obviously you cared to read it. :rolleyes:
RadarBob
07-19-2002, 03:41 PM
Off hand I'd say write a function.
First, add an "onchange" or "onblur" to your object:
<input type="text" name="z1" size="15" maxlength="50" onchange="ShiftFocus(formname.c1)">
The function is simple:
function ShiftFocus(fieldname) {
fieldname.focus();
} // function ShiftFocus()
Passing a parameter makes the function flexible and easier for you to tweak the behavior of your code.
Could also call the above function to give focus upon page load:
<body .... onLoad="ShiftFocus(document.forms[0].a1)">
In those primary text boxes you could give focus to the other through that same function:
<input type="text" name="c1" size="15" maxlength="50" onchange="ShiftFocus (document.myform.a1)">
<input type="text" name="a1" size="15" maxlength="50" onchange="ShiftFocus (document.myform.c1)>
NOTE: if you use "onblur" above to mutually change focus you will get caught in a trap of endless focusing on only these two fields.
ANOTHER possibility for the mix is to use "tabindex=" to specify, for each field, the order the fields are visited as you press the TAB key.
RadarBob
07-19-2002, 03:44 PM
The above subjects either have absolutely nothing to do with the question itself, or are grossly incomplete (ie: "loops"). When asking for help, enter a subject that summarizes your question, period! Don't use silly, incomplete, or "bait" subjects.
Absofreakingloutly right-on :thumbsup:
ksridhar69
07-19-2002, 03:45 PM
my question is how to enter into c1,a1 text box by using control or function keys
RadarBob
07-19-2002, 04:06 PM
I hate it when I answer the wrong question.:o But man, that was a good answer! :thumbsup:
the KeyPress event in Javascript is what you need. Seems IE and NN hanldle it differently. It's new to me too, so I can't write an answer of the top of my head... Of 3 books I looked at I found the answer here: Javascript Complete by Steven Holzner. It's available online at http://www.netlibrary.com/index.asp
have fun with it!
tamienne
07-19-2002, 08:30 PM
What about just using tabindex?
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.