Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-24-2003, 03:43 PM   #1
Registered: Apr 2003
Posts: 178

Rep: Reputation: 30
How to define Text box as numeric

The box that has a label numeric input:

1) In this box is there a way to define to where it is numeric
and not text. For example

<INPUT type="number" name="Numeric_Data" maxlength=4>
instead of

<INPUT type="text" name="Numeric_Data" maxlength=4>


The box that has a label numeric input:

2) When I enter 0000, it is treated as 0000 and not as 0
In Visual Basic or Access, when a numer is entered with many zero is treated as one 0. How do you do this in Javascript ?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<TITLE>Only Numeric value is allowed</TITLE>

<SCRIPT lang="JScript">

function show_key_value()

function showDialog(txt)
   var temp=new String();
   var temp2=""
   var count=0;
   // event.keyCode == 8 is a backspace

   //if (!(event.keyCode >=48 && event.keyCode <=57))
   if (!(event.keyCode == 48 || event.keyCode == 49 ||
         event.keyCode == 50 || event.keyCode == 51 ||
	 event.keyCode == 52 || event.keyCode == 53 ||
	 event.keyCode == 54 || event.keyCode == 55 ||
	 event.keyCode == 56 || event.keyCode == 57 ||
	 event.keyCode == 8))
       temp=Numeric_Data.value;//preserve the current contents of text field
       alert("Only numeric is allowed")
             if(temp.charAt(count) >= '0' && temp.charAt(count) <= '9')



<LABEL for="Numeric input" tabindex="3">Numeric input:</LABEL>
<INPUT type="number" name="Numeric_Data" maxlength=4 onkeyup='showDialog(Numeric_Data.value)'>

<LABEL for="Event Key Code Number" tabindex="3">Keyboard input:</LABEL>
<INPUT type="text" id="Keyboard" maxlength=4 onkeyup='show_key_value()'>



Last edited by Linh; 09-24-2003 at 03:46 PM.
Old 09-24-2003, 03:59 PM   #2
LQ Newbie
Registered: Sep 2003
Location: stralsund/germany
Distribution: gentoo
Posts: 14

Rep: Reputation: 0
try to round up the value


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
openoffice 2- how do i create a text box? lefty.crupps Linux - Software 2 11-02-2005 10:29 PM
C - xlib - scrollable text box serbet Linux - Software 1 09-22-2004 01:01 PM
C Xlib scrollable text box serbet Programming 0 09-22-2004 03:13 AM
Text Box popup agallant Programming 2 08-16-2004 12:56 PM
How to create an array text box to lessen the codes Linh Programming 1 10-18-2003 10:31 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:45 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration