?
Solved

number format in form text input box

Posted on 2003-03-25
7
Medium Priority
?
261 Views
Last Modified: 2008-02-26
is there a tag that will automatically format data in a text input as a 2 decimal float?

example:
  enter 1; result 0.01
  enter 4; result 0.14
  enter 7; result 1.47

i can figure out the multiplication part to move the decimal, but i run into issues when adding more than 1 zero to the end.
0
Comment
Question by:cMetz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8206634
Here are a few places to look:

http://www.w3schools.com/js/js_math.asp

http://www.irt.org/xref/Math.htm

Fritz the Blank
0
 

Author Comment

by:cMetz
ID: 8206713
these help but do not address the bigger issue.  after re-reading my question i realize what i should have asked.  the main problem i run into is when you try to enter zeros.

if you try to enter 38.10, it shows up as 38.1 because the browser truncates all unneccessary digits.  i am looking for a way for the browser to understand that the data in that text field is to be understood as a float with 2 decimal places regardless of its value.
0
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 200 total points
ID: 8206749
if you always grab your values as parseFloat(), they will be interpreted as numbers, but I am not sure if that helps you.

Fritz the Blank
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 12

Expert Comment

by:lil_puffball
ID: 8207475
This will do the trick:

<script>
function format(obj){
text=obj.value.split('.').join('')
if(text.charAt(text.length-1)=='0')
{obj.value=text/100+'0'}
else
{obj.value=text/100;}
}
</script>

<form>
<input type="text" onKeyUp="format(this)">
</form>
0
 
LVL 1

Expert Comment

by:umangjoshi
ID: 8208290
you have two way

[1] consider you have a <form name="f".....
and a textfield name="no"

now in javascript pls try following

var num;
num = f.no.value * 1;
//this alert shows you which value stored in num
alert(num);

//if f.no.value is not a number, num contains value like NaN, may be other

if (num == NaN)
{
   .......
}
else
{
   ........



[2] define a function which check f.no.value, character by character and if any invalid symbole returns false (boolean)
}
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10149874
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: fritz_the_blank {http:#8206749}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question