It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

javascript woes

javascript woes

Postby wessie on Fri Feb 23, 2007 8:56 am

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!
wessie
 
Posts: 0
Joined: Fri Feb 23, 2007 8:55 am

Postby mwa103 on Fri Feb 23, 2007 7:40 pm

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
mwa103
100+ Club
 
Posts: 206
Joined: Mon Mar 07, 2005 10:55 pm

Postby mwa103 on Fri Feb 23, 2007 7:50 pm

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.
mwa103
100+ Club
 
Posts: 206
Joined: Mon Mar 07, 2005 10:55 pm


Who is online

Users browsing this forum: No registered users and 7 guests