PDA

View Full Version : append a text input into div box



devinrayolsen
05-25-2008, 05:38 AM
How would one go about passing a "HTML text input form elements content" over to a text node that will be appended to a div box?

In other words if a person were to type into say a textarea how would I make the text they are typing show up in a div box else where on the page?

Please anyone!
Thanks.

jscheuer1
05-25-2008, 06:36 AM
First of all, a textarea and a text input are two different things. I will assume that you mean a text input:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function xFerText(el, id){
document.getElementById(id).firstChild.nodeValue=el.value;
}
</script>
</head>
<body>
<input type="text" onchange="xFerText(this, 'output');" onkeyup="xFerText(this, 'output');">
<div id="output">&nbsp;</div>
</body>
</html>

Or:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function xFerText(id1, id2){
document.getElementById(id2).firstChild.nodeValue=document.getElementById(id1).value;
}
</script>
</head>
<body>
<input id="input" type="text">
<div id="output">&nbsp;</div>
<input type="button" value="Go" onclick="xFerText('input', 'output');">
</body>
</html>