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?
I tried this, but I got an error said the array is not defined. All Helps are appreciated.
<cfscript >
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 < Price.length; ++index) {
if (!isNaN(Price[index]) && !isNaN(Quantity[index]))
{
Totals = Totals + (Price[index] * Quantity[index]);
}
}
$('total').value = Totals;
return true;
}
</cfscript>
<cfform>
<cfinput type="Button" name="submit" value="Calculate Order" onclick="#calculateTotal()#">
<cfinput type="Text" name="total" disabled="true" label="Total $" size="5">
</cfform