PDA

View Full Version : Replace input field problem


david_va
10-18-2006, 03:24 PM
I am trying to take an input element and replace it with the value from a table. My problem is that when I replace the element, it becomes a text field instead of an input text field.

Following is the input text code:

<td>
<bean:define id="errlastname" name="userEnrollmentHeaderForm"
property="errorLastName" type="java.lang.String"/>
<div id="lastName"><html:text property="lastName" size="50" maxlength="50"
styleClass="<%= errlastname %>"/></div>
</td>

Following is the java script that loads the last name value
document.getElementById("lastName").innerHTML = ln;

When last name is replaced, the input text field actually becomes a text field and users can not make any changes.

Kor
10-18-2006, 05:14 PM
try
document.getElementById("lastName").firstChild.value=ln;

david_va
10-18-2006, 05:54 PM
Thank you, that worked.

I guess that when changing the value of an input fiels, you use "child.value", but when changing the value text, you can use "innerHTML".

Kor
10-18-2006, 06:06 PM
No. innerHTML is not a DOM method, even it is a crossbrowser one. innerHTML simply replace everything inside an element whith the desired content (text or html code).

the firstChild means the input element which is nested in your DIV (but only if there is no empty space there). So that firstChild.value changes only the value of that input, not the input element entirely.

Google for javascript DOM to learn more

david_va
10-19-2006, 03:40 PM
Thank you for the information. This has helped me alot. I was playing around with overriding input text fields and text areas. I think I am starting to see what is happening!!