<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: FillTextareafromSelect code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 21 Aug 2008 15:21:38 GMT</pubDate>
    <description>DZone Snippets: FillTextareafromSelect code</description>
    <item>
      <title>JavaScript Fill Textarea from HTML Select not working with FireFox or Opera but does in IE6</title>
      <link>http://snippets.dzone.com/posts/show/4465</link>
      <description>//&lt;br /&gt;//  Fill textarea with keywords from HTML Select element&lt;br /&gt;//&lt;br /&gt;&lt;br /&gt;This code DOES work in I.E6 (on my machine (XP pro), but doesn't work in Firefox 2.0.0.4 or Opera 9.0.2&lt;br /&gt;&lt;br /&gt;The idea is to be able to either type in the text area directly or choose from a list of saved words in the select box. When a new choice is made from the select, it automatically gets inserted into the text area.&lt;br /&gt;&lt;br /&gt;With Firefox , when the page is first loaded, I can choose from the select control and it works until I type something in the text area, and then it stops working.&lt;br /&gt;&lt;br /&gt;With Opera 9.02, the select control doesn't work at all.&lt;br /&gt;&lt;br /&gt;IE6, works fine.&lt;br /&gt;&lt;br /&gt;Any hints tips, appreciated, as I'm a novice with javascript / DOM programming.&lt;br /&gt;&lt;br /&gt;I quite possibly am not using the most correct / efficient document.XXX calls here.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Mike&lt;br /&gt;&lt;br /&gt;You can test it at http://mstramba.com/fb5.html&lt;br /&gt;&lt;br /&gt;///////////////&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;html&gt;&lt;br /&gt;&lt;head&gt;&lt;br /&gt;  &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;&lt;br /&gt;  &lt;style type="text/css"&gt;textarea {  height:200px; width:50%;}&lt;/style&gt;&lt;br /&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;br /&gt;&lt;br /&gt;function htmlData(selectValue,targetTextArea)&lt;br /&gt;{&lt;br /&gt;//   alert("select box changed to : '" + selectValue + "'");&lt;br /&gt;&lt;br /&gt;   var txtNode=document.createTextNode(selectValue);&lt;br /&gt;   var textArea=document.getElementById(targetTextArea);&lt;br /&gt;   textArea.appendChild(txtNode);&lt;br /&gt;}&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;/head&gt;&lt;br /&gt;&lt;br /&gt;&lt;body&gt;&lt;br /&gt; &lt;form method="post"&gt;&lt;br /&gt; &lt;select name="country" id="selbox" onchange="htmlData(this.value,'content')" /&gt;&lt;br /&gt;   &lt;option value="#"&gt;-Select-&lt;/option&gt;&lt;br /&gt;   &lt;option value="SuperCaliFragilisticExpiAliDocius"&gt;SuperCaliFragilisticExpiAliDocius&lt;/option&gt;&lt;br /&gt;   &lt;option value="Discombombulatively"&gt;Discombombulatively&lt;/option&gt;&lt;br /&gt;   &lt;option value="I don't understand how this can be happening"&gt;I don't understand how this can be happening&lt;/option&gt;&lt;br /&gt; &lt;/select&gt;&lt;br /&gt;&lt;br /&gt; &lt;textarea name="content" id="content"&gt;Type some text or choose words from the select control&lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt; &lt;input type="submit" /&gt;&lt;br /&gt;&lt;/form&gt;&lt;br /&gt;&lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 24 Aug 2007 23:38:44 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4465</guid>
      <author>mstram (Mike Stramba)</author>
    </item>
  </channel>
</rss>
