title: CakePHP: calling an external Javascript function
body: <p>I have the following code that works as shown here: <code>http://jsfiddle.net/rBd53/12/</code></p>
  
  <p>HTML/JS code in one file:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      var textBlocks = new Array(
          'Select from the list to change this box',
          'Text block two',
          'Text block three'); 
  
      function changeText(form) {
          var ind = form.qwer.selectedIndex;
          document.getElementById("display").innerHTML=textBlocks[ind]; 
      }
  &lt;/script&gt;
  
  &lt;form&gt;
      &lt;select name="qwer" onChange="changeText(this.form);"&gt;
          &lt;option value="0"&gt;Select&lt;/option&gt;
          &lt;option value="1"&gt;One&lt;/option&gt;
          &lt;option value="2"&gt;Two&lt;/option&gt;
      &lt;/select&gt;
      &lt;br&gt;
      &lt;div id="display"&gt;Select from the list to change this box&lt;/div&gt; 
  &lt;/form&gt;
  </code></pre>
  
  <p>How do I change this code to make it work properly with CakePHP 1.3? I have created a <code>test_js.js</code> file under <code>app/webroot/js</code> and put the <code>&lt;script&gt;...&lt;/script&gt;</code> portion in there. I also have <code>echo $scripts_for_layout;</code> in <code>app/views/layouts/default.ctp</code> in the <code>&lt;head&gt;</code>. </p>
  
  <p>I'm guessing stuff in my element (.ctp) file is incorrect. The dropdown menu and text below appear, but the text is not dynamically changed according to the option selected. I did the following.</p>
  
  <pre><code>&lt;?php echo $this-&gt;Html-&gt;script('test_js', array('inline'=&gt;false)); ?&gt;
  &lt;form&gt;
  &lt;select name="qwer" onChange="changeText(this.form);"&gt;
      &lt;option value="0"&gt;Select&lt;/option&gt;
      &lt;option value="1"&gt;One&lt;/option&gt;
      &lt;option value="2"&gt;Two&lt;/option&gt;
  &lt;/select&gt;
  &lt;br&gt;
  &lt;div id="display"&gt;Select from the list to change this box&lt;/div&gt; 
  &lt;/form&gt;
  </code></pre>