Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Javascript to add to the existing text in a textarea
    primarykey
    data
    text
    <p>I need to have an "Add Features" button that will append the following text to the already existing text in a textarea:</p> <pre><code>&lt;b&gt;Features:&lt;/b&gt; &lt;ul&gt; &lt;li&gt;Feature 1 here&lt;/li&gt; &lt;li&gt;Feature 2 here&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>It needs to appear in html form, so that the user can see the tags as well as their contents. Here is the HTML I'm using:</p> <pre><code>&lt;tr class="addItemFormDark"&gt; &lt;td class="descriptionLabel"&gt; &lt;p&gt;Description:&lt;/p&gt; &lt;/td&gt; &lt;td&gt; &lt;textarea name="description" id="addItemDescription" cols="77" rows="6"&gt;&lt;/textarea&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr class="addItemFormDark"&gt; &lt;td colspan="2"&gt; &lt;input type="button" onclick="addFeatures('addItemDescription')" value="Add Features"/&gt; &lt;/td&gt; &lt;/tr&gt; </code></pre> <p>...and here is the JavaScript I'm using:</p> <pre><code>function addFeatures(id) { var contents = document.getElementById(id).innerHTML; contents += "&lt;b&gt;Features:&lt;/b&gt;\r&lt;ul&gt;\r\t&lt;li&gt;Feature 1 here&lt;/li&gt;\r\t&lt;li&gt;Feature 2 here&lt;/li&gt;\r&lt;/ul&gt;"; document.getElementById(id).innerHTML = contents; } </code></pre> <p>Now here is that part I'm having trouble with. If the textarea is empty, as it is to begin with, the desired text will be added to the textarea fine, and this can be repeated multiple times with each block of text being successfully added after the last.</p> <p>However, if the user types anything in the box, whether into the empty text area, or after the successful addition of one of the desired blocks of code, this completely disables the button. It will then no longer add anything to the textarea until the page is refreshed.</p> <p>I got exactly the same result if I used JQuery's .append method and gave the textarea and button an id.</p> <p>Can anyone help?</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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