Adding ajax to text field in node edit form
You don't need ajax, you can do this with jQuery or javascript. Something like this might work.

First, create an external js file and set up your change events.

jQuery(document).ready(
    function()
    {
        jQuery("#field2").change(subtract_fields);
        jQuery("#field1").change(subtract_fields);

        function subtract_fields()
        {
            if (jQuery("#field1").value != "" &amp;&amp; jQuery("#field2").value != "")
            {
                return jQuery("#field1").value - jQuery("#field2").value;
            }

            return "";
        }
    }
);


Next, load the external js file using drupal_add_js.

Clear your cache and voila.