HighDots Forums  

Re: Add data to a input box

Javascript JavaScript language (comp.lang.javascript)


Discuss Re: Add data to a input box in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Evertjan.
 
Posts: n/a

Default Re: Add data to a input box - 07-27-2003 , 04:58 PM






Blaine HIlton wrote on 27 jul 2003 in comp.lang.javascript:

Quote:
I realize this sounds basic, but I have been having trouble getting
code that will fill in a text box. What I have is a text box in a
form where a person enters a price in the form "XX.YY" However if its
$50 they may just enter 50 and then I would need the javascript to
detect that they have changed the box with focus and if there is no
decimal, add a decimal and two zeros.

Any code snippits are a point in the right direction would be
appreciated.

<input
onchange="this.value=(+this.value).toFixed(2)">

toFixed() can be a bit buggy, test it thoroughly.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


Reply With Quote
  #2  
Old   
Grant Wagner
 
Posts: n/a

Default Re: Add data to a input box - 07-28-2003 , 11:04 AM






"Evertjan." wrote:

Quote:
Blaine HIlton wrote on 27 jul 2003 in comp.lang.javascript:

I realize this sounds basic, but I have been having trouble getting
code that will fill in a text box. What I have is a text box in a
form where a person enters a price in the form "XX.YY" However if its
$50 they may just enter 50 and then I would need the javascript to
detect that they have changed the box with focus and if there is no
decimal, add a decimal and two zeros.

Any code snippits are a point in the right direction would be
appreciated.


input
onchange="this.value=(+this.value).toFixed(2)"

toFixed() can be a bit buggy, test it thoroughly.
Because toFixed() can be buggy, a more complete solution for producing
formatted numbers is available at:

<url: http://jibbering.com/faq/#FAQ4_6 />

--
Quote:
Grant Wagner <gwagner (AT) agricoreunited (DOT) com
* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 6/7 and Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.