How to change text in textbox
Ok this is wheat I have so far. IF someone could help me out. I had to change the color of the background when you click on a button. And I also have to Use document.getElementById('yourelementid') to both find the value of the textarea and to change the basic text created in the div. But I don't know how to do that i have been researching online. I think i am getting a little confused about where to p开发者_高级运维ut things at in here thanks.
Here is what I have so far....
<!DOCTYPE html PUBLIC "-//W3C//DTD Xhtml 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http:www.w3.org/1999/xhtml">
<head>
<title>DOM</title>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1" />
<script language="JavaScript">
<!-- Begin
function newbg(thecolor)
{
document.bgColor=thecolor;
}
// End -->
</script>
<body>
<h3>DOM Assignment Examples</h3>
<div>
<form>
<h4>Change background color to:</h4>
<input type="radio" value="White" onclick="newbg('white');">white<br/>
<input type="radio" value="Blue" onclick="newbg('blue');">Blue<br />
<input type="radio" value="Beige" onclick="newbg('Beige');">Beige<br />
<input type="radio" value="Yellow" onclick="newbg('yellow');">Yellow<br />
</form>
</div>
<br />
<br />
<br />
<h4>add text to this box change the text below:</h4>
<TEXTAREA NAME="" ROWS="10" COLS="40" onBlur="blurHandlerRouting">
You will change this text
</TEXTAREA> <br />
<INPUT TYPE="button" NAME="button" Value="Click" onClick="testResults(this.form)">
</body>
</html>
The contents of a <textarea>
can be manipulated using .html()
in jQuery or .innerHTML
in vanilla JavaScript.
Your HTML should contain the id=""
attribute:
<textarea id="mytextarea">Text to be changed</textarea>
And the JavaScript:
document.getElementById('mytextarea').innerHTML = "New Text";
To change the background and the textarea you would try this:
function = testResults(){
document.getElementById("yourTextBoxId").style="background:red;"; //Change the background color to red.
document.getElementById("yourTextAreaId").value="your another text for the textarea"
}
精彩评论