View Full Version : Form/Div problem

09-27-2005, 10:40 AM
I have a form field called "age" and it is a text field. I have javascript take the current year and subtract it by the age field and show the user's birth date. This is shown in a div.

Here is my javascript code:

<script type="text/javascript">
function showDOB()
var NewText = document.getElementById("DynamicText").value;
var DivElement = document.getElementById("TextDisplay");
DivElement.innerHTML = 2005 - NewText;
// -->
Then, I have this for my form and div fields:

<td>*Age:</td><td><input id="DynamicText" value="Numbers Only!" class="lighthover" onMouseOver="style.backgroundColor='#999900';" onMouseOut="style.backgroundColor='#009900';" onfocus="if(this.value=='Numbers Only!')this.value='';" onKeyUp="showDOB();" type="text" name="age" /></td>
<td>*Date Of Birth:</td><td width="10%"><font face="Times New Roman, Times, serif" color="#006600" size='3px'><div class="lighthover" onMouseOver="style.backgroundColor='#999900';" onMouseOut="style.backgroundColor='#009900';" id="TextDisplay">&nbsp;</div></font></td>
When I first load the page, it is a blank div, but when I type it changes. That is good. My problem is that when I clear the age field, the div goes to "2005". How I do get the div to go blank when the age field is changed to blank?

09-27-2005, 12:14 PM
Put an if in like this:
if (NewText >0)
DivElement.innerHTML = 2005 - NewText;
DivElement.innerHTML = ''; // thats two single quotes


09-28-2005, 12:32 AM
Thanks I'll try it when I get home from school today!