Meaning of textarea? how to fill one?

I am trying to populate textarea using javascript, I found that textarea does not have a value tag, and <textarea ..></textarea> not an option, since I cannot use it with javascript.

Edit:

 content.document.getElementsByName("cr-work-desc0").innerHTML = "125645"; content.document.getElementsByName("cr-work-urls0").textContent = "this is some sample text"; content.document.getElementsByName("infringing-urls0")[0].setAttribute("value","testing to"); 
+6
source share
3 answers

Just set the field value via document.getElementById('thefield').value = 'value' .

+7
source

For the input element , the default value indicated by the value attribute, and the current value indicated by the value property.

A textarea is different. The default value is specified in the text node, which is a child of this element.

i.e:.

 <textarea>this is the default value</textarea> 

However, the current value is still determined by the value property.

 document.getElementById('thefield').value = 'value'; 

... although the value attribute is missing for textarea elements.


You can change the default value ( input.setAttribute("value", "new value") or textarea.innerHTML = "new value" ), which will be:

  • Change the displayed value if it has not changed (for example, when entered by the user)
  • Change the value that the reset control will have if the reset button is activated

... but usually you need to change (and read) the current value, which will always be input.value / textarea.value .

+1
source

Try the following code

 document.getElementById("aa").innerHTML="Blah Blah"; 
 <textarea id="aa"></textarea> 

Both innerHTML and value work fine.

You can write something instead of aaaa

-1
source

Source: https://habr.com/ru/post/947039/


All Articles