-5

I have got a variable in javascript called 'signature'

var signature;

//(Data is here)

document.write(signature) 

In HTML, I have the following:

<div id="siggen">
<textarea id="content" cols="80" rows="10"></textarea>

What i want is when i click generate button the variable signature appers in text area. Can anyone help?

3 Answers3

2

I think you need like:

var signature = "Hello";
function addVal(){


    document.getElementById('content').value = signature
}
<div id="siggen">
<textarea id="content" cols="80" rows="10"></textarea>
 <button id="btnClick" onclick="addVal()">Click</button> 
ketan
  • 19,129
  • 42
  • 60
  • 98
0

You can use JQuery :

$("#content").val(signature)

See val-vs-text-for-textarea

Community
  • 1
  • 1
FredMi
  • 34
  • 2
0

Your question is not quite clear but I assume you want to do something like this.

First in your html add a textarea and a button with these properties. Use disabled only if you want to make the text area disabled.

<textarea disabled id="displaytext"></textarea>
<button  onclick="buttonFunction()">Click !</button>

Now in your javascript file, write the buttonFunction() to display the value in signature variable in the text area.

var signature = "This is the content to display";

function buttonFunction() {
  document.getElementById("displaytext").innerHTML = signature;
}

This is the result. The text will be displayed when you click the button. output

Ishara Amarasekera
  • 1,387
  • 1
  • 20
  • 34