I'm trying to put 3 or 4 buttons that would help registering users to enter their e-mail addresses. Basically what I need is when they click "@gmail.com" button, their address will be completed with that. I ended up with a code like this:
function insertText(elemID, text) {
var elem = document.getElementById(elemID);
elem.innerHTML += text;
}
<form>
<textarea id="txt1"></textarea>
<input type="button" value="Insert some text" onclick="insertText('txt1', 'Hello');">
</form>
However as you can try and see, it's not working when a user enters some text inside and clicks the button. I want to resolve this issue with minimum amount of script and preferably without jQuery.
Note: I will place this code snippet inside a block, but the textarea might be not in the same block. Is that possible to still make use of it?