A reader yesterday asked me an interesting question. Using ColdFusion 8 and bindings, is it possible to do simple mathematics? For example, he wanted something like this:

<input type="text" name="res" bind="{field1}*{field2}">

While that isn't possible, you can do it using cfajaxproxy. (Oh my sweet cfajaxproxy - is there anything you cannot do???) Consider the following example:

<cfajaxproxy bind="javascript:doMultiply({first},{second})" /> <script> function doMultiply(x,y) { document.getElementById("result").value = x*y; } </script>

<form> <input id="first" size="3"> X <input id="second" size="3"> = <input id="result">

</form>

The form has 3 fields. The first two are for the numbers I'll be multiplying. The last field is for the result. I use the cfajaxproxy tag to bind to the first two fields. I run the JavaScript function, doMultiply, whenever first or second changes. And that's it! I should probably add a check to see if x and y are numeric, but you get the idea.