PDA

View Full Version : Automatic go to next input (Password / Serial key)


Public2
08-09-2006, 10:48 AM
You might know it from several games such as Diablo 2. You have to write down your cd product key in 3 different input boxes, and it varies in length e.g. first box has 4 numbers, second has 3 and last has only 2.

Then when you’re finished writing down your 9 numbers it will automatic change focus to the submit button.

You can do that in JavaScript, if you have an activation code or something else on your webpage, and it's quite simple to actually.

Place this code in your head section on your page:


<script type="text/javascript">
function toUnicode(elmnt,content)
{
if (content.length==elmnt.maxLength)
{
next=elmnt.tabIndex
if (next<document.forms[0].elements.length)
{
document.forms[0].elements[next].focus()
}
}
}
</script>


Place this HTML code in your body:


<form name="form" form methode="post" value="active.asp">

<input size="4" tabindex="1" name="first"
maxlength="4" onkeyup="toUnicode(this,this.value)">

<input size="3" tabindex="2" name="Second"
maxlength="3" onkeyup="toUnicode(this,this.value)">

<input size="2" tabindex="3" name="Third"
maxlength="2" onkeyup="toUnicode(this,this.value)">
<br>
<br>
<input type="submit" name="submit" value="submit"

</form>

Bomber9900
07-22-2008, 01:46 PM
But how do I ensure that it only goes to another page if they input the right serial code.

binaryWeapon
07-23-2008, 03:15 AM
This is not a script for serial-code validation, that would require a server-side language and a database usually. This is a script which conveniently switches the focus to the next input box once a specific number of characters has been filled out. It is just a convenience for the user so that he doesn't have to stop typing and move his cursor to the next box.