|
It is currently Fri Dec 05, 2008 2:23 pm
|
View unanswered posts | View active topics
|
Page 1 of 1
|
[ 3 posts ] |
|
| Author |
Message |
|
wessie
|
Post subject: javascript woes Posted: Fri Feb 23, 2007 9:56 am |
|
Joined: Fri Feb 23, 2007 9:55 am Posts: 1
|
|
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 |
|
 |
|
mwa103
|
Post subject: Posted: Fri Feb 23, 2007 8:40 pm |
|
 |
| 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 |
|
 |
|
mwa103
|
Post subject: Posted: Fri Feb 23, 2007 8:50 pm |
|
 |
| 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 |
|
 |
|
Page 1 of 1
|
[ 3 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 12 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
|
|
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:
|
|
|