View Full Version : How to Reset innerHTML?

01-30-2006, 10:16 AM
I am using the following code to try to replace "hello" inside DIV. When I type in the field, it should clear 'hello' and then display what I type in the field one letter at a time. But it doesn't clear hello and it just show what I type in an additional line, what's wrong?
many thanks.

<script language='javascript'>
function mirror(){
<input name="txtarea" id="txtarea" type="text" onKeyUp="mirror();">
<div name="theDiv" id="theDiv">hello

Bill Posters
01-30-2006, 10:46 AM
Works fine for me in FF1.5/Mac.
In which browser are you experiencing problems?

01-30-2006, 11:18 AM
Yes, it should work in all the modern browsers. At least if you use a doctype and the correct type for the script tag:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function mirror(v){
<input type="text" onkeyup="mirror(this.value)"><br>
<div id="theDiv">Hello!</div>

Bill Posters
01-30-2006, 11:22 AM
Have you checked whether your browser is javascript disabled?

But it doesn't clear hello and it just show what I type in an additional line
I presume from the fact that it is adding the text, that js is enabled.


I guess you just realised that too. ;)

01-30-2006, 11:23 AM
yea... I have had already corrected the post...