0

There is a website with a textarea in which I want to populate some default text as soon as the website loads but the problem is the textarea tag doesn't have an ID.

document.getElementsByTagName("textarea").value="default text" ;  
<textarea name="details"  rows="5" cols="25" style="width: 100%; overflow: auto;"></textarea>

I've tried the below code but it isn't working . Do you have any suggestions on how to achieve this ?

document.getElementsByTagName("textarea").value="default text" ;  

jsfiddle

TA.

rax
  • 34
  • 4
  • 1
    `var textarea = document.querySelector('textarea[name="details"]');` – andriusain Feb 13 '20 at 05:00
  • 1
    I do not think the answers linked to are the best BTW – andriusain Feb 13 '20 at 05:01
  • Solved. I've used below code instead. var menuItems = document.getElementsByTagName('textarea'); for (var menuItemIndex = 0 ; menuItems.length ; menuItemIndex ++) { var currentMenuItem = menuItems[menuItemIndex]; currentMenuItem.value = "default value"; } thanks. – rax Feb 13 '20 at 05:02

0 Answers0