Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Is There an example on how to acces numbers only in Text Field?

Reply
Thread Tools

Is There an example on how to acces numbers only in Text Field?

 
 
Anonieko Ramos
Guest
Posts: n/a
 
      10-03-2004
You can use the OnKeypress javascript event
Evaluate the keypress on the function

>
>
>

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>(Wiki)
browse My Wiki Home

</title>
<LINK REL=StyleSheet HREF="wiki.css" TYPE="text/css" >
<SCRIPT TYPE="text/javascript">
<!--
// copyright 1999 Idocs, Inc. http://www.idocs.com
// Distribute this script freely but keep this notice in place
function numbersonly(myfield, e, dec)
{
var key;
var keychar;

if (window.event)
key = window.event.keyCode;
else if (e)
key = e.which;
else
return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key== ||
(key==9) || (key==13) || (key==27) )
return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
return true;

// decimal point jump
else if (dec && (keychar == "."))
{
myfield.form.elements[dec].focus();
return false;
}
else
return false;
}

//-->
</SCRIPT>


</head>
<body>


<FORM ACTION="/cgi-bin/mycgi.pl" METHOD=POST>
U.S. ZIP Code:
<INPUT NAME="dollar" SIZE=5 MAXLENGTH=5
onKeyPress="return numbersonly(this, event)">
<INPUT TYPE=SUBMIT VALUE="go">
</FORM>

</body>
</html>
<noscript>
<script language="jawascript">
 
Reply With Quote
 
 
 
 
Michael Winter
Guest
Posts: n/a
 
      10-03-2004
On 3 Oct 2004 02:26:48 -0700, Anonieko Ramos <> wrote:

Subject: Is There an example on how to acces numbers only in Text Field?

> You can use the OnKeypress javascript event
> Evaluate the keypress on the function


Are you trying to ask a question, or make a statement? It seems the
latter. In either case, it would be nice to actually present valid markup.

The best approach, in my opinion, is to not even try to prevent
keystrokes. This can lead to confusion or irritation if the user doesn't
realise that a keystroke has been ignored, and before it's suggested,
alerting the user to it isn't a good solution. That'll lead to more
frustration.

Instead, validate the field after the user has finished entering their
value. It's far more kind to the user and more reliable.

[snipped malformed rubbish]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
allowing only certain computers acces to the wirless network =?Utf-8?B?cGhpbA==?= Wireless Networking 2 12-29-2005 09:39 PM
'example.com' == 'example.com.' => false... is this intended? Sam Roberts Ruby 15 02-07-2005 04:36 PM
Not able to acces authentication tab wireless networkconnection pr =?Utf-8?B?bm9vcmQ0NTM=?= Wireless Networking 3 10-15-2004 07:59 PM
Only numbers in text Box Mariame ASP .Net 2 08-19-2004 09:37 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57