Jumping from one input text to the next input text automatically
Dear my friends.... I am writing a web program with Mozilla (as the only one client) and Java Script for Mozilla (developer.netscape.com). I want if the user type the date (tanggal) after 2 character than the cursor will jump to the next input text automatically. I used "tanggal.focus()" but no expected result comes. Anybody would be so nice to tell me the solution? Thank you so much. ps. Here is my listing program below. ======= <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <script language="JavaScript"> function cek(fieldnya){ var namavar = fieldnya.name; var nilaivar = fieldnya.value; var panjangnya = nilaivar.length; if (namavar=='tanggal'){ if (nilaivar<1 || nilaivar>31){ alert("Ungültiges Datum"); } if (panjangnya>2){ alert("Datum hat nur 2 Zahlen"); } } if (namavar=='bulan'){ if (nilaivar<1 || nilaivar>12){ alert("Ungültiges Monat"); } if (panjangnya>2){ alert("Monat hat nur 2 Zahlen"); } } if (namavar=='tahun'){ if (nilaivar<0){ alert("Ungültiges Jahre"); } if (panjangnya>4){ alert("Jahre hat nur 4 Zahlen"); } } } function pindahsorot(pindah){ var namavarpindah = pindah.name; var nilaivarpindah = pindah.value; var panjangnyapindah = nilaivarpindah.length; //alert("Panjangnya udah : "+panjangnyapindah+" namavarpindah : "+namavarpindah+ //" nilaivarpindah : "+nilaivarpindah); if (namavarpindah=='tanggal'){ if (panjangnyapindah>=2){ //alert("pindah akh"); this.form.bulan.select(); this.form.bulan.focus(); } } } </script> <body> <form name="customer"> 14. Broschüre verschickt : <input type=text name=tanggal size=2 onChange="cek(this.form.tanggal)" onKeyUp="pindahsorot(this.form.tanggal)" >. <input type="text" name="bulan" size=2 onChange="cek(this.form.bulan)">. <input type=text name=tahun size=4 onChange="cek(this.form.tahun)"><FONT color=Green size=1><BLINK>---><U>Format : dd.mm.jjjj </BLINK></FONT></U> </form> </body> </html> -- _____________________________________________________________ Web-based SMS services available at http://www.operamail.com.
From your mailbox to local or overseas cell phones.
Powered by Outblaze
IMHO your doing it wrong. Allow the user to enter the whole date in 6 or 8 character format then parse it for whatever use you need. Otherwise you wind up testing for a character string of length two then testing for each character being a digit. CWSIV On Wed, 2004-03-17 at 06:21, Prabu Subroto wrote:
Dear my friends....
I am writing a web program with Mozilla (as the only one client) and Java Script for Mozilla (developer.netscape.com).
I want if the user type the date (tanggal) after 2 character than the cursor will jump to the next input text automatically. I used "tanggal.focus()" but no expected result comes.
Anybody would be so nice to tell me the solution?
Thank you so much.
ps. Here is my listing program below. ======= <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <script language="JavaScript"> function cek(fieldnya){ var namavar = fieldnya.name; var nilaivar = fieldnya.value; var panjangnya = nilaivar.length;
if (namavar=='tanggal'){ if (nilaivar<1 || nilaivar>31){ alert("Ungültiges Datum"); } if (panjangnya>2){ alert("Datum hat nur 2 Zahlen"); } }
if (namavar=='bulan'){ if (nilaivar<1 || nilaivar>12){ alert("Ungültiges Monat"); } if (panjangnya>2){ alert("Monat hat nur 2 Zahlen"); } }
if (namavar=='tahun'){ if (nilaivar<0){ alert("Ungültiges Jahre"); } if (panjangnya>4){ alert("Jahre hat nur 4 Zahlen"); } }
}
function pindahsorot(pindah){ var namavarpindah = pindah.name; var nilaivarpindah = pindah.value; var panjangnyapindah = nilaivarpindah.length;
//alert("Panjangnya udah : "+panjangnyapindah+" namavarpindah : "+namavarpindah+ //" nilaivarpindah : "+nilaivarpindah);
if (namavarpindah=='tanggal'){ if (panjangnyapindah>=2){ //alert("pindah akh"); this.form.bulan.select(); this.form.bulan.focus(); } }
} </script>
<body> <form name="customer"> 14. Broschüre verschickt : <input type=text name=tanggal size=2 onChange="cek(this.form.tanggal)" onKeyUp="pindahsorot(this.form.tanggal)" >. <input type="text" name="bulan" size=2 onChange="cek(this.form.bulan)">. <input type=text name=tahun size=4 onChange="cek(this.form.tahun)"><FONT color=Green size=1><BLINK>---><U>Format : dd.mm.jjjj </BLINK></FONT></U> </form> </body> </html> -- _____________________________________________________________ Web-based SMS services available at http://www.operamail.com.
From your mailbox to local or overseas cell phones.
Powered by Outblaze
participants (2)
-
Carl William Spitzer IV
-
Prabu Subroto