PDA

View Full Version : small & simply code needs fixing


sappo
08-03-2005, 04:30 AM
Hi Guys,

I'm trying somethink that's new to me. I want to get the text in a textarea and display it live on the same page. This is what I have thought it's not working:

<!--
function bob()
{
var newText = document.getElementsByName("textarea").value();
var sap = document.getElementsByTagName("h1")[0];
sap.firstChild.nodeValue = newText;
}
-->
</script>

<form name="form1" id="form1" method="post" action="">
<p>
<textarea name="textarea1" id="textarea1" onchange="bob()"></textarea>
</p>
</form>
<p><h1>bob</h1></p>

Does anyone fancy fixing this for me? please?

Now as for the live update I thought I would use a setinterva() are there any better ways of doing this?

Thanks,

Sapl

_Aerospace_Eng_
08-03-2005, 05:07 AM
How is this?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
<!--
function bob()
{
var newText = document.getElementById('form1').textarea1.value;
var sap = document.getElementsByTagName("h1")[0];
sap.firstChild.nodeValue = newText;
}
-->
</script>
</head>

<body>
<form id="form1" method="post" action="">
<p>
<textarea name="textarea1" id="textarea1" onkeyup="bob()"></textarea>
</p>
</form>
<h1>bob</h1>
</body>
</html>
Your main problem was your newtextvar, there is no such thing as getElementsByName, or even a value function.

sappo
08-03-2005, 05:09 AM
nice one cheers

_Aerospace_Eng_
08-03-2005, 05:10 AM
Oh one other thing, you can't have a header tag inside of a paragraph.