Randy Webb wrote :
engwar said the following on 10/1/2005 7:00 AM:
I'd like to know if it's possible to change the contents of a div tag
based on something the user is doing.
Yes.
For example. If there is a text box on a page and the user types his or
her name can I update an existing div tag to show what they've typed
in?
<input type="text"
onchange="document.getElementById('myDiv').innerHT ML=this.value">
Personally, I would recommend to use childNodes[0].nodeValue or
firstChild.nodeValue rather since the input only takes text; there is
really no need to use innerHTML here. Also, the onchange could be
correct but the onkeyup (in order to see each typed character) event
attribute might be what the OP is looking for. The problem with the
onchange event attribute is that the user will only see the result when
*leaving* the input.
So, another possible solution:
<div> <span id="NameTyped"> </span></div>
<form action="">
<p>Type in your name: <input name="InputOfName" type="text"
onkeyup="document.getElementById('NameTyped').firs tChild.nodeValue =
this.value;" value=" "></p>
</form>
Tested and working with a strict Doctype decl. in Mozilla 1.9a1, Opera
8.50, MSIE 6.
Gérard
--
remove blah to email me