Reputation: 977
I'm trying to add the value of a paragraph to a text area using javascript. This is my code at the moment. I can't quite seem to get it to work. Any help is appreciated
<html>
<head>
</head>
<body>
<button value="this is a length definition" onclick="reveal(this.value)"> hi</button>
<script type="text/javascript">
function reveal(value)
{
var text = value;
document.outputtext.value += value;
}
</script>
<table>
<tr>
<td><textarea name="outputtext"></textarea></td>
</tr></table>
</body>
</html>
Upvotes: 0
Views: 2078
Reputation: 99
<html>
<head>
</head>
<body>
<button value="this is a length definition" onclick="reveal(this.value)"> hi</button>
<script type="text/javascript">
function reveal(value)
{
var text = value;
document.getElementById("outputtext").value += text;
}
</script>
<table>
<tr>
<td><textarea id="outputtext"></textarea></td>
</tr></table>
</body>
</html>
Upvotes: 1
Reputation: 177851
Your textarea is not part of the document. Also your button value is not a paragraph.
document.getElementById("outputtext").value
(recommended) or document.formName.outputtext.value
ordocument.getElementsByName("outputtext")[0].value
Here is the code using ID
<html>
<head>
</head>
<body>
<button value="this is a length definition" onclick="reveal(this.value)"> hi</button>
<script type="text/javascript">
function reveal(value) {
document.getElementById("outputtext").value += value;
}
</script>
<table>
<tr>
<td><textarea id="outputtext"></textarea></td>
</tr></table>
</body>
</html>
Upvotes: 2
Reputation: 408
Code change to:
<html>
<head>
</head>
<body>
<button value="this is a length definition" onclick="reveal(this.value);"> hi</button>
<script type="text/javascript">
function reveal(value)
document.getElementById("outputtext").value += value;
}
</script>
<table>
<tr>
<td><textarea id="outputtext"></textarea></td>
</tr></table>
</body>
</html>
Upvotes: 0
Reputation: 13956
shoud change to
<textarea id="outputtext"></textarea>
then code change to
document.getElementById('outputtext')
good luck
You can use name but you have to call getElemntsByName() and receive an array of element
Upvotes: 1