I created this fiddle so that you can see the struggle I have.
My HTML
<form action="" method="post" role="form" name="my-form-name">
<button class="html-button">Link me</button>
<textarea name="x" id="post-text" rows="17" required="required"></textarea>
<button type="submit" class="submit-button-form">submit form</button>
</form>
JS:
$(".html-button").on("click", function () {
var urls = prompt("Add a link", "http://");
var setText = $("#post-text").val(urls);
// Adding prompt text into my input field
$("#post-text").val(urls);
});
This code works, but it only works once. Meaning: if I add a hyperlink it works the first time, but when I want to add another link, it doesn't insert it. Instead, it just changes whatever I had put in first + the additonal plain text I am adding to the textarea.
My question: how can I make this link addition independent of what I type in the textarea (plain text) and make sure that I can add more links without it changing the other ones in the textarea?
Fiddle: https://jsfiddle.net/vaxqsztj/1/