title: How to call a JavaScript function from "ColdFusion button"
body: <p>I have a prototype function. I would like to wrap it around function tag and then call it from a button in a cfform. Is it possible to do it? and how would I do it?</p>
  
  <p>I tried this, but I got an error said the array is not defined. All Helps are appreciated.</p>
  
  <pre><code>&lt;cfscript &gt;
      function calculateTotal(){
          var Price = Array();
          var Quantity = Array();
              $$('.x-grid3-col-PRICE').each(function(el){Price[Price.length] = el.innerHTML; });
              $$('.x-grid3-col-QUANTITY').each(function(el){Quantity[Quantity.length] = parseInt(el.innerHTML); });
  
          var Totals = 0;
          for (var index = 0; index &lt; Price.length; ++index) {
              if (!isNaN(Price[index]) &amp;&amp; !isNaN(Quantity[index]))
               {
               Totals =  Totals + (Price[index] * Quantity[index]);
                      }
  
                  }
          $('total').value = Totals;
         return true;
      }
      &lt;/cfscript&gt;
  
  &lt;cfform&gt;
       &lt;cfinput type="Button" name="submit" value="Calculate Order" onclick="#calculateTotal()#"&gt;
      &lt;cfinput type="Text" name="total" disabled="true" label="Total $" size="5"&gt;
  &lt;/cfform
  </code></pre>