Hi,
I have a text box that holds floating numbers how do i format it so that the user will not be able to enter values greater than 99.99.
I want to insert a '.' when the length of the textbox is 2.
i tried to do it this way but while clearing the text using back space button it showed problems
//struts text field//
html:text styleId="txtId" property="txt" onkeyup="countChar(this.id)" maxlength="5"
//script code// - function countChar(obj)
-
if(document.getElementById(obj).value.length==2)
-
document.getElementById(obj).value=document.getElementById(obj).value+'.';
-
thanks
Anil
6 5903
Instead of checking onkeyup, just check when the form is submitted.
If you want to check onkeyup, you will need to check that the first two characters are numbers and that there is not already a dot in place. I go for simplicity - just use a regular expression for checking float numbers.
Half of your problem is solved...
Fix the remaining yourself...
[HTML]<script type="text/javascript">
function format99Dot99(inp) {
var valid = 0;
nums = new Array('1','2','3','4','5','6','7','8','9','0','.') ;
var v = '';
var x = '';
for (var i=0; i<inp.value.length; i++) {
x = inp.value.charAt(i);
for (var j=0; j<=10; j++)
if (x==nums[j]) valid = 1;
if (valid) v += x;
valid = 0;
}
//if (v>=10) v+='.';
if (v>99.99)
while (v > 99.99)
v = v%100;
inp.value = v;
}
</script>
<input type="text" onkeyup="format99Dot99(this)" maxlength=5>[/HTML]
You can use the code on line 13, but it won't let the user delete the dot once added, as you already tried the similar.
Instead of checking onkeyup, just check when the form is submitted.
If you want to check onkeyup, you will need to check that the first two characters are numbers and that there is not already a dot in place. I go for simplicity - just use a regular expression for checking float numbers.
Hi,
Am not that good in javascript. Can you sho me how it can be done using the reg expression.
Hi,
Am not that good in javascript. Can you sho me how it can be done using the reg expression.
In this case, you need something like:
See this link which shows you how to use regular expressions in JavaScript.
In this case, you need something like:
See this link which shows you how to use regular expressions in JavaScript.
Hi,
Thanks for the reply but will this be dynamic, I have a text field for interest so the values the user enters must be within 99.99. how do i implement the expression you have given. i went through the site link you gave and the live example in it. there it was not dynamic implementation ... i hope you can understand. I have seen sites where when i enter my date of birth the '-' comes in between by itself thus avoiding some level of validation. I want to do the same
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Rookie |
last post by:
I need to display several columns of numbers in a textbox. I wish to
display the columns with the decimal point position aligned vertically.
I have found that the # digit placeholders do not...
|
by: Alexander Schmidt |
last post by:
Hi,
I am not very familiar with C++ programming, so before I do a dirty hack I
ask for a more elegant solution (but only the usage of STL is allowed, no
special libs).
So I need to read a file...
|
by: geskerrett |
last post by:
In the '80's, Microsoft had a proprietary binary structure to handle
floating point numbers, In a previous thread, Bengt Richter posted
some example code in how to convert these to python floats;...
|
by: Bill Reed |
last post by:
I'm trying to add numbers from a text file and find the average. The
numbers in the file are:
25 50 75 100
I expect the result to be 62.50 but I get 85.00. I've twiddled with
the condition...
|
by: Subrahmanyam Arya |
last post by:
Hi Folks ,
I am trying to solve the problem of reading the numbers correctly
from a serial line into an intel pentium processor machine .
I am reading 1 byte and 2byte data both positive...
|
by: vijay |
last post by:
Hello,
What happens to float variable in loops. For example,
float f=8.7;
if(f<8.7)
printf("less");
else if(f==8.7)
printf("equal");
else if(f>8.7)
|
by: seep |
last post by:
hi
i m finding following error on the code that i wants to use to get all record from table via store procedure with paging. the error is :
Input string was not in a correct...
|
by: MM |
last post by:
Hi to all,
I'm trying to import a tab separated values file onto Excel with the
following script:
import csv
from pyExcelerator import *
w = Workbook()
worksheet = w.add_sheet('sim1')
|
by: Bill Cunningham |
last post by:
I am interested in writing a numeric text reader. This only reads
numbers of securities and stores them. Nice practice. I have determined that
these functions are needed.
isalpha, isdigit,...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |