MitchellVII
asked on
Is there a way to format decimal places in a Textbox with a number in it?
Hi,
I am putting a textbox on my form and would like it to automatically show a format of 0.0.
For instance, if the person just enters a 12, the texbox should change to 12.0 automatically.
Is this possible?
M
I am putting a textbox on my form and would like it to automatically show a format of 0.0.
For instance, if the person just enters a 12, the texbox should change to 12.0 automatically.
Is this possible?
M
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
mmark,
Any idea on what that code that forces the decimal point would look like?
Any idea on what that code that forces the decimal point would look like?
Hi,
You can use the following Javascript code to achieve that,
<HTML>
<HEAD>
<script language="JavaScript">
function formatnum(){
var valu1 = parseInt(document.test.txt 1.value);
document.test.txt1.value = valu1.toFixed(1);
}
</script>
</HEAD>
<BODY BGCOLOR=#FFFFFF>
<form name="test">
<input type="text" name="txt1" onchange="formatnum()"/>
</form>
</BODY>
</HTML>
Regards - RM.
You can use the following Javascript code to achieve that,
<HTML>
<HEAD>
<script language="JavaScript">
function formatnum(){
var valu1 = parseInt(document.test.txt
document.test.txt1.value = valu1.toFixed(1);
}
</script>
</HEAD>
<BODY BGCOLOR=#FFFFFF>
<form name="test">
<input type="text" name="txt1" onchange="formatnum()"/>
</form>
</BODY>
</HTML>
Regards - RM.
initial value would be like
<input type="text" name="txt1" value="0.0" onchange="formatnum()"/>
<input type="text" name="txt1" value="0.0" onchange="formatnum()"/>
ASKER
thanks rm,
Is there a way I can add an argument to the function so that I can pass the text field name to it? This needs to work in about 50 places.
M
Is there a way I can add an argument to the function so that I can pass the text field name to it? This needs to work in about 50 places.
M
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hey bubble,
would I actually type "this" in the argument or the name of the text field?
M
would I actually type "this" in the argument or the name of the text field?
M
Yes, will return the textbox object to the function.
ASKER
I bow before you superior knowledge oh great one - works like a charm :)
Mitchell
Mitchell
ASKER
Oh yeah, also meant to ask you:
How do I format a field so that it returns a dollar amount?
So that if they entered 125000 it would show $125,000.00?
Thanks :)
M
How do I format a field so that it returns a dollar amount?
So that if they entered 125000 it would show $125,000.00?
Thanks :)
M
have an integer / decimal form setup (archaeic, but it works)