admin管理员组

文章数量:1327929

I'm trying to create a script that uses the input.

<textarea id="textareabox" name="textarea1" placeholder="Start here..."></textarea>

function hintbutton4() {
    document.getElementById("textareabox").innerHTML = 'ID=textareabox';
}

I've got this, but I don't know how to grab the text as input... How can I do it? What should I search for?

I want the input from the text area used in the script in the last part 'ID=textareabox'. That's all.

I'm trying to create a script that uses the input.

<textarea id="textareabox" name="textarea1" placeholder="Start here..."></textarea>

function hintbutton4() {
    document.getElementById("textareabox").innerHTML = 'ID=textareabox';
}

I've got this, but I don't know how to grab the text as input... How can I do it? What should I search for?

I want the input from the text area used in the script in the last part 'ID=textareabox'. That's all.

Share Improve this question edited May 9, 2022 at 2:01 Peter Mortensen 31.6k22 gold badges110 silver badges133 bronze badges asked Feb 24, 2017 at 22:05 baswijdenesdotbaswijdenesdot 3151 gold badge2 silver badges13 bronze badges 6
  • 3 Like most form fields, there is no innerHTML on a textarea, just a value property. – Heretic Monkey Commented Feb 24, 2017 at 22:09
  • do you want to put text into the text area? – lonewarrior556 Commented Feb 24, 2017 at 22:10
  • No I want to use the text in the text area in my javascript – baswijdenesdot Commented Feb 24, 2017 at 22:10
  • If you're trying to change the text typed into textarea try: document.getElementById("textareabox").value = 'INPUT'; Also see here: w3schools./jsref/dom_obj_textarea.asp – Luke Commented Feb 24, 2017 at 22:13
  • Use this fiddle to know what you want... jsfiddle/shemdani/rwzx8j50/1 – spooky Commented Feb 24, 2017 at 22:32
 |  Show 1 more ment

1 Answer 1

Reset to default 2

Here is a basic example using pure JavaScript.

Essentially, from what I understand, you are trying to populate a textarea with JavaScript as well as get the value.

Code Pen: http://codepen.io/anon/pen/mWyOMq

JavaScript

function getText() {
    var text = document.getElementById("textareabox").value;
    alert(text);
}

function setText() {
    var text = document.getElementById("textareabox").value = 'Hello, World!';

}

HTML

<div>
    <textarea id="textareabox" name="textarea1" placeholder="Start here..."></textarea>
    <input type="button" value="Get Text" onclick="getText()" />
    <input type="button" value="Set Text" onclick="setText()" />
</div>

本文标签: Use textarea input in JavaScriptStack Overflow