...

View Full Version : How to Reset innerHTML?



dealmaker
01-30-2006, 10:16 AM
Hi,
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.


<head>
<script language='javascript'>
function mirror(){
document.getElementById("theDiv").innerHTML=document.getElementById("txtarea").value;
}
</script>
</head>
<body>
<input name="txtarea" id="txtarea" type="text" onKeyUp="mirror();">
<div name="theDiv" id="theDiv">hello
</div>
</body>

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

Kor
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">
<html>
<head>
<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){
document.getElementById('theDiv').innerHTML=v;
}
</script>
</head>
<body>
<input type="text" onkeyup="mirror(this.value)"><br>
<div id="theDiv">Hello!</div>
</body>
</html>

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.


[edit]

I guess you just realised that too. ;)

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum