This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Text Field and default values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Text Field and default values" Watch "Text Field and default values" New topic

Text Field and default values

ryan headley
Ranch Hand

Joined: Jun 28, 2000
Posts: 156
I have a few text fields setup in a web application. When the user click the calculate button it needs to take the fields add them together and then populate another cell with that value.
(kinda like a spreadsheet).
Is there anyway to initialize the value of the text field to 0 (zero)without having it show the 0 (zero)??
If I set value=0 in the tag, the 0 shows up. If I set a defaultValue=0 I still get NaN as a result if any field is left blank.

Ryan Headley<br /><a href="" target="_blank" rel="nofollow"></a>
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I would suggest storing the values of your text fields in variables before performing the calculation. Then perform the calculation on the variables instead of the text field values themselves. That way you can validate them and set them to 0 if they are "" before using them, and the user will not see the value in the text field.
[This message has been edited by Bodie Minster (edited March 21, 2001).]
ryan headley
Ranch Hand

Joined: Jun 28, 2000
Posts: 156
Thanx, that's what we did, we just set the value="" then ran if statements on each variable and if == "" then we set it = to 0
I agree. Here's the link:
subject: Text Field and default values
Similar Threads
Problems with Calendar.clear() method
enable and disable a text field
Data File Format & Schema File
URLy 1.1.2 - Reading the DB
how to set value of text field