user580523
user580523

Reputation:

Javascript Textarea Issue

I'm importing data from youtube into a textarea using Javascript.

If you I simply place my Javascript code onto a blank area it displays the information fine, but for some reason it doesn't allow me to paste a same code into a textarea.

Here is my code:

<textarea rows="10" id="bandsvideodescription" name="bandsvideodescription">
<script type="text/javascript">
  function youtubeFeedCallback( data )
  {
    document.writeln( '' + data.entry[ "media$group" ][ "media$description" ].$t.replace( /\n/g, '' ) + '' );
  }
</script>
</textarea>

Any help would be great,

Thanks.

Upvotes: 0

Views: 210

Answers (3)

darkylmnx
darkylmnx

Reputation: 2071

you can't put script tags <script> in a textarea you can't even put any html tag in a textarea.

It will consider it as the default value ;)

And escaping it with &gt; our &lt; will nt change anything because it's already escaped in the textarea to show it as simple text

Upvotes: 0

Quentin
Quentin

Reputation: 943098

Textareas are defined as:

<!ELEMENT TEXTAREA - - (#PCDATA)       -- multi-line text field -->

They can only contain PCDATA, which means no elements (including <script> elements).

Move the script to after the control, then get a reference to it (e.g. with document.getElementById) and set its value property instead of trying to write it out as the document loads.

Upvotes: 1

Wladimir Palant
Wladimir Palant

Reputation: 57651

Your script is interpreted as HTML code. You should escape angle brackets, like this:

<textarea rows="10" id="bandsvideodescription" name="bandsvideodescription">
&lt;script type="text/javascript"&gt;
  function youtubeFeedCallback( data )
  {
    document.writeln( '' + data.entry[ "media$group" ][ "media$description" ].$t.replace( /\n/g, '' ) + '' );
  }
&lt;/script&gt;
</textarea>

Upvotes: 0

Related Questions