title: XSS attack not working in textarea tag
body: <p>I had earlier coded a simple chat application using PHP and AJAX. In that, once a user sends a chat, it first goes to php and from there it is saved in the database. I use AJAX on the client side to query the db at regular intervals for new messages. Those messages I eventually am showing in a . </p>
  
  <p>So in my client side code, I have a recMsg variable which is I have set as </p>
  
  <pre><code>recMsg = recMsg + value['chattime'] + ' &lt;@' + value['chatby'] + '&gt; ' + value['chat'] + '\r\n';
  </code></pre>
  
  <p>where value is an array with value['chat'] having the actual chat message. </p>
  
  <p>Later I am setting text area as the follows </p>
  
  <pre><code>$('#received').val(recMsg + $('#received').val());
  </code></pre>
  
  <p>where received is the id of the  tag. The code for textarea (when I view the source code in browser) is </p>
  
  <pre><code>&lt;textarea id="received" rows="15" cols="150"&gt;&lt;/textarea&gt;
  </code></pre>
  
  <p>Now to try out xss attack, I am entering the following as my chat </p>
  
  <pre><code>&lt;/textarea&gt;
  &lt;script&gt;
  alert("Hi");
  &lt;/script&gt;
  &lt;textarea&gt;
  </code></pre>
  
  <p>but instead of showing me an alert box, it just shows the full message in the textarea along with the tags (it does not treat any of the tags as special and just treats them as normal text to be displayed). I tried changing the javascript such recMsg was just the chat message, and also tried using .innerHTML but no success. </p>
  
  <p>So my questions are
  1) Is the attack failing because I am changing the value of textarea after it has been rendered?</p>
  
  <p>2) Is it possible to carry out an XSS in this way. How can I change the javascript code to enable this attack? </p>
  
  <p>3) Unrelated questions - when I change the DOM element using AJAX and if I view the source, I don't see any change (for example, textarea is still empty after I have received several chats). Any reason why this is the case? </p>
  
  <p>Thanks for your replies</p>