LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 09-24-2003, 04:43 PM   #1
Linh
Member
 
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 ?

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

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


<SCRIPT lang="JScript">
<!--

function show_key_value()
 {
   alert(event.keyCode)
 }


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")
       Numeric_Data.value=""
         while(count<temp.length)
          {
             if(temp.charAt(count) >= '0' && temp.charAt(count) <= '9')
             Numeric_Data.value=Numeric_Data.value+temp.charAt(count);
             count++;
          }
     }
 }

//-->
</SCRIPT>
</HEAD>

<BODY>

<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()'>

<BR>

</BODY>
</HTML>

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

Rep: Reputation: 0
try to round up the value
 
  


Reply


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 11:29 PM
C - xlib - scrollable text box serbet Linux - Software 1 09-22-2004 02:01 PM
C Xlib scrollable text box serbet Programming 0 09-22-2004 04:13 AM
Text Box popup agallant Programming 2 08-16-2004 01:56 PM
How to create an array text box to lessen the codes Linh Programming 1 10-18-2003 11:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:21 AM.

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