Click to See Complete Forum and Search --> : Tab Emulation with period key


KissLizzyCooper
08-14-2003, 10:41 AM
Hi all...

Here is my situation...I want to emulate the tab key behavior on a page...I want the behavior to act like standard Windows TCP/IP when entering the IP address...You hit ## and then the (.) key and it advances to the next box...

I have the JavaScript written to advance the focus...But...Here is my problem...When the next form element receives focus, it has the (.) appended to the front of the element...So if I had 99 as the value of the form element, when I hit the (.) key, the *next* form element will display .99...

How do I fix...???...

KLC

diamonds
08-14-2003, 12:47 PM
from my experiance, people are more likely to respond if you have a script trhat you want to fix or customize.


Lets start with a script like this:
<input name="0" type="text" onKeyPress="keypress(1)" size="4">

what happens here is when the focus is in that textfield, it will execute the function keypress(1)
I put the 1 there to tell the function that the focus is currently on the first text box.

Here is the HTML to start you off:
<input name="0" type="text" id="0" onKeyPress="keypress(1)" size="4">.
<input name="1" type="text" id="1" onKeyPress="keypress(2)" size="4">.
<input name="2" type="text" id="2" onKeyPress="keypress(3)" size="4">.
<input name="3" type="text" id="3" onKeyPress="keypress(0)" size="4">

I am working on the javascript function right now:)

diamonds
08-14-2003, 12:53 PM
that was my 100'th post:) (let's celebrate!)

diamonds
08-14-2003, 01:19 PM
this is supposed! to work!

<script>
function keypress(dest){
var keycode;
if (window.event) keycode = window.event.keyCode;
if (keycode == 46) {// 48 is the keycode for the perion (" . ")

if(dest='1'){
document.thisform.ip1.focus();

}else if(dest='2'){
document.thisform.ip2.focus();

}else if(dest='3'){
document.thisform.ip3.focus();

}else if(dest='0'){
document.thisform.ip0.focus();
}

}
}
</script>
<form name="thisform">
<input name="ip0" type="text" onKeyPress="keypress('1')" size="4">
<input name="ip1" type="text" onKeyPress="keypress('2')" size="4">
<input name="ip2" type="text" onKeyPress="keypress('3')" size="4">
<input name="ip3" type="text" onKeyPress="keypress('0')" size="4">
</form>

, however, it does not(it does once)!

can someone else help!

diamonds
08-14-2003, 01:27 PM
you could also put the IP into 1 box, than have javascript get the value, and split it amoung the periods, into an array.

somthing like this:
split('123.45.67.89','.');

diamonds
08-14-2003, 01:34 PM
Originally posted by KissLizzyCooper
I have the JavaScript written to advance the focus...
opps... I see...
Well, just after you advance the focus, do this:

document.form.element.value="";

this will make the value of the element equel to "", removing any text in the field!