Go Back   CodingForums.com > :: Client side development > JavaScript programming > Post a JavaScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-09-2006, 10:48 AM   PM User | #1
Public2
New to the CF scene

 
Join Date: Aug 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Public2 is an unknown quantity at this point
Automatic go to next input (Password / Serial key)

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:
Code:
<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:
Code:
<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>
Public2 is offline   Reply With Quote
Old 07-22-2008, 01:46 PM   PM User | #2
Bomber9900
New to the CF scene

 
Join Date: Jul 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Bomber9900 is an unknown quantity at this point
But how do I ensure that it only goes to another page if they input the right serial code.
Bomber9900 is offline   Reply With Quote
Old 07-23-2008, 03:15 AM   PM User | #3
binaryWeapon
Regular Coder

 
Join Date: Sep 2007
Location: AZ, USA
Posts: 685
Thanks: 6
Thanked 46 Times in 46 Posts
binaryWeapon is on a distinguished road
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.
binaryWeapon is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:58 AM.


Advertisement
Log in to turn off these ads.