2

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.

6
  • 3
    Like most form fields, there is no innerHTML on a textarea, just a value property. Commented Feb 24, 2017 at 22:09
  • do you want to put text into the text area? Commented Feb 24, 2017 at 22:10
  • No I want to use the text in the text area in my javascript 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.com/jsref/dom_obj_textarea.asp Commented Feb 24, 2017 at 22:13
  • Use this fiddle to know what you want... jsfiddle.net/shemdani/rwzx8j50/1 Commented Feb 24, 2017 at 22:32

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.