Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change text in textbox

Tags:

javascript

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 put 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>
like image 757
norris1023 Avatar asked Apr 16 '11 01:04

norris1023


People also ask

How do you modify text in text boxes?

To format the text in the text box, select it, and then Control + Click the text and select Font. To add different effects to the text box, select the text box, and use the options on the Shape Format tab (such as changing the text direction or aligning the text at the top, middle or bottom of the text box).

How do I change the default text in a text box?

Right-click the text box that has the formats you want to use as the default. On the shortcut menu, click Format Text Box, and then click the Colors and Lines tab. Select the Apply settings to new text boxes check box. Click OK.

How do I change the properties of a text box in Word?

After you insert a text box on a form template, you can customize it by accessing and changing its properties and settings in the Text Box Properties dialog box. To open the dialog box, on the form template, double-click the text box whose properties you want to change.

How do I edit text in a text box in Outlook?

On the Insert tab, in the Text group, click Quick Parts. Right-click anywhere in the gallery pane and choose Organize and Delete from the context menu. In the dialog box that appears, select the entry you want to modify and click Edit Properties… Make the changes and click OK to save them.


2 Answers

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";
like image 92
njbair Avatar answered Sep 20 '22 01:09

njbair


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"
}
like image 21
Galled Avatar answered Sep 21 '22 01:09

Galled