Flash Games

 FAQ   Search   Members   Groups   User Control Panel      Login 

It is currently Fri Jan 09, 2009 5:15 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: javascript woes
PostPosted: Fri Feb 23, 2007 9:56 am 
Offline

Joined: Fri Feb 23, 2007 9:55 am
Posts: 0
Hi all,

I've written a small script to allow the user to enter a telephone number (like 0690-HELP) and it would convert it to the numeric equivalent (ie. 0690-4357). But i've got a problem with the javascript giving me a message saying one of my form objects "is null or not an object".

I've included the code below and if anyone could be so kind as to assist i'd really appreciate it!

=====================================================

<html>
<head>
<script type="text/javascript">
<!--
function noNumbers(e)
{
var keynum
var keychar
var numcheck

if(window.event) // IE
{
keynum = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which
}
keychar = String.fromCharCode(keynum)
var parsed_number = "";
numcheck = /\d/
if(!numcheck.test(keychar))
{
keychar = keychar.toUpperCase();
if((keychar == "A") || (keychar == "B") || (keychar == "C"))
{
parsed_number = 2;
}
else if((keychar == "D") || (keychar == "E") || (keychar == "F"))
{
parsed_number = 3;
}
else if((keychar == "G") || (keychar == "H") || (keychar == "I"))
{
parsed_number = 4;
}
else if((keychar == "J") || (keychar == "K") || (keychar == "L"))
{
parsed_number = 5;
}
else if((keychar == "M") || (keychar == "N") || (keychar == "O"))
{
parsed_number = 6;
}
else if((keychar == "P") || (keychar == "Q") || (keychar == "R")|| (keychar == "S"))
{
parsed_number = 7;
}
else if((keychar == "T") || (keychar == "U") || (keychar == "V"))
{
parsed_number = 8;
}
else if((keychar == "W") || (keychar == "X") || (keychar == "Y")|| (keychar == "Z"))
{
parsed_number = 9;
}

document.Form1.txtConvert.value += parsed_number;
}
else
{
document.Form1.txtConvert.value += parsed_number;
}

}
//-->
</script>
</head>
<body>
<form id="Form1">
<input type="text" name="txtNumber" onkeypress="return noNumbers(event)" />
<input type="text" name="txtConvert" />
</form>
</body>
</html>
====================================================

Any assistance is appreciated!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 23, 2007 8:40 pm 
Offline
100+ Club

Joined: Mon Mar 07, 2005 11:55 pm
Posts: 206
Change <form id="Form1"> to <form name="Form1"> or if you want leave the id and just add the name="Form1". It shouldn't hurt either way. Hope this helps.

-Mike


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 23, 2007 8:50 pm 
Offline
100+ Club

Joined: Mon Mar 07, 2005 11:55 pm
Posts: 206
Also just noticed, you have a typo in your code.
You have:
document.Form1.txtConvert.value += parsed_number;

twice. The second one (the one in the else) should read:
document.Form1.txtConvert.value += keychar;

Fix these things and the script will work.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 23 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group - Flash Games - TNX Invitation Code - TNX Review

Welcome to DEVPPL.com
You are not logged in, which means that you can't post in the forums.
Click here to Register

If you are a current member here on DEVPPL, please login below:

User:
Pass:
Log me on automatically each visit: