Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fill up a textbox with javascript?

I am very new to javascript and I was trying to populate a textbox from html with javascript but for some reason isn't working. This is what I have:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Relations</title>
  <link rel="stylesheet" href="kandi.css" type="text/css" media="screen">
  
  <script src="myscript.js"></script>
  
  <body>
	<h1 align="center" style="font-family:Arial;" >RELATION TAGGING </h1>
	<textarea id="your_textarea" rows="15" cols="160">
	</textarea>
  
  </body>
  </head>
</html>

Javascript:

var textarea = document.getElementById("your_textarea");
textarea.innerHTML = "testing123";
like image 611
Gannina Avatar asked May 01 '26 07:05

Gannina


1 Answers

Textareas are not text inputs. Whereas input elements store the input in an attribute: <input value="foo">, textareas get them as content: <textarea>foo</textarea>. Use this instead:

textarea.textContent = "testing123"
like image 190
Amadan Avatar answered May 02 '26 21:05

Amadan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!