I have two textareas. When the user clicks a text link, ie “Add to Cart”, how would I get the values of both textareas to be pasted into a third textarea, separated by a delimiter like ” — “, and finally for a new page to load once the function is complete?
The code I have so far is:
JS:
$('#addtocart').click(function() {
var text1 = $("#inputA").val();
var text2 = $("#inputB").val();
var text3 = text1 + "\n--\n" + text2;
$("#personalisedmsg").val(text3);
};
HTML:
<textarea id="inputA" class="limited" rows="6">Your top message here.</textarea><br />
<textarea id="inputB" class="limited" rows="6">Your bottom message here.</textarea><br />
<textarea id="personalisedmsg"></textarea>
<br><br>
<a id="addtocart" href="#">Add to Cart.</a>
Thanks for any help.
To do the text field stuff…
To load a new page doesnt make sense, what are you doing with textbox3 data before? Do you instead want to submit a form? If so, you can do like this for example (assuming only one form in document)…
or to just reload a new page if you really want to then…
Important Note
When you use the click handler of a link, if the link has a
hrefproperty set you should ensure you are cancelling the default action (i.e. the reloading of a new page)…Working Example
Here is a working example
note that after copying your JQuery code I had to add an additional close bracket
)at the end for it to run correctly