Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have this exact problem. So far I have tried</p> <pre><code>$('#addofferlink').click(function(){ var offer = "#OFFER_"+$('#offer_id').val()+"#"; $('#message').append(offer); }); </code></pre> <p>I have also tried,</p> <pre><code> $('#addofferlink').click(function(){ var e = $('#message').html(); var offer = "#OFFER_"+$('#offer_id').val()+"#"; $('#message').html(e+offer); }); </code></pre> <p>The problem seems to be that if the user types into the textarea (#message) then clicks the button to add the offer link, nothing is displayed. Looking at the source, using Firebug, I can see that the actual text contained in the textarea is being amended, but not displayed on the screen.</p> <p>It seems that the javascript is changing the html contents of the tag, but the browser is storing the currently typed contents in memory (i assume) or elsewhere.</p> <p>Updating the textarea using val(e+offer) will remove the entered text and replace it with the offerlink, and using innerHTML = e+offer doesn't work at all, showing no change in the textarea.</p> <hr> <p>I've managed to sort this!</p> <p>My thinking revolved around the fact that because tag contains the text, and has it's own closing tag, that I would have to get it's contents using .html().</p> <p>By using .val() to get the contents of the field you can then pull and update the contents simply. I ended up with the following,</p> <pre><code> $('#addofferlink').click(function(){ var e = $('#message').val(); var offer = "#OFFER_"+$('#offer_id').val()+"#"; $('#message').val(e+offer); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload