How can I apply a discount for a non required field on a form?
<p>I have a form that has several fields and factors that are calculating prices for one of the programs our charity offers. We have added a new field that is named "AHLA". What I need to do for now is allow any 6 digit code that is typed into that field to apply a 5% discount to the monthly rate. Any help is appreciated, and I have left out all of the form, and just included the functions/JavaScript of the existing page.</p>

<pre><code>&lt;script type="text/javascript"&gt;
function validateEmail(x) { 
    var atpos=x.indexOf("@");
    var dotpos=x.lastIndexOf(".");
    if (atpos&lt;1 || dotpos&lt;atpos+2 || dotpos+2&gt;=x.length)
      {
        return false;
      } else {
          return true;
      }
    }
    $(document).ready(function () {

        var specified_number_of_rooms = $('#item9_text_1');
        var billing_terms = $('#item27_select_1');
        var select_your_region = $('#item7_select_1');
        var generalManagerCheckbox = $('#item42_0_checkbox');
        var shippingAddressCheckbox = $('#item61_0_checkbox');
$.fn.hideOptionGroup = function() {
$(this).hide();
$(this).children().each(function(){
$(this).attr("disabled", "disabled").removeAttr("selected");
});
$(this).appendTo($(this).parent());

}

$.fn.showOptionGroup = function() {
$(this).show();    
$(this).children().each(function(){
$(this).removeAttr("disabled" );
});
$(this).prependTo($(this).parent());
$(this).parent().animate({scrollTop:0},0);
}       
    $("#item15_select_1_us").hideOptionGroup();
    $("#item15_select_1_ca").hideOptionGroup();
    $("#item15_select_1_ha").hideOptionGroup();
        // This function will fire when "number of rooms" specified by the end user changes.

        $(specified_number_of_rooms).change(function () {
            if (prereqsToCompute() == true) {
                var result = compute();
                update(result);
            } else {
                clear();
            }
        });

        $(specified_number_of_rooms).blur(function () {
            if (prereqsToCompute() == true) {
                var result = compute();
                update(result);
            } else {
                clear();
            }
        });

        // This function will fire when "billing terms" option is changed.

        $(billing_terms).change(function () {
            if (prereqsToCompute() == true) {
                var result = compute();
                update(result);
            } else {
                clear();
            }
        });

        // This function will fire when the "select your region" option is changed.

        $(select_your_region).change(function () {
            if (prereqsToCompute() == true) {
                var result = compute();
                update(result);
            } else {
                clear();
            }
        });

        $(generalManagerCheckbox).click(function () {             // this function fires if "general manager is authorized payee" checkbox is checked/clicked.
            if ($('#item42_0_checkbox').is(':checked')) {
                $('#item38_text_1').val($('#item31_text_1').val());     // general manager first name populated with authorized payee first name
                $('#item39_text_1').val($('#item32_text_1').val());     // general manager last name populated with authorized payee last name
                $('#item41_text_1').val($('#item43_text_1').val());     // general manager title with authorized payee title
                $('#item40_email_1').val($('#item34_email_1').val());   // general manager email with authorized payee email
            } else {
                $('#item38_text_1').val("");    // general manager first name emptied/reset
                $('#item39_text_1').val("");    // general manager last name emptied/reset
                $('#item41_text_1').val("");    // general manager title emptied/reset
                $('#item40_email_1').val("");   // general manager email emptied/reset
            }
        });



        $(shippingAddressCheckbox).click(function () {             // this function fires if "shipping is same as billing" checkbox is checked/clicked.
            if ($('#item61_0_checkbox').is(':checked')) {
                $('#item57_text_1').val($('#item13_text_1').val());     // shipping address populated with billing address
                $('#item55_text_1').val($('#item14_text_1').val());     // shipping city populated with billing city
                $('#item60_select_1').val($('#item15_select_1').val()); // shipping state populated with billing state
                $('#item56_text_1').val($('#item16_text_1').val());     // shipping zip populated with billing zip
            } else {
                $('#item57_text_1').val("");            // shipping address emptied/reset
                $('#item55_text_1').val("");            // shipping city emptied/reset
                $('#item60_select_1').val("Alabama");   // shipping state emptied/reset
                $('#item56_text_1').val("");            // shipping zip emptied/reset
            }
        });

        // ------------------------------------ function clear() ------------------------------------
        //
        // This function clears the per-invoice rate, monthly rate, and number of rooms from the 
        // read-only fields on the form.

        function clear() {

            var rooms = $('#item21_text_1');
            var monthlyRate = $('#item23_text_1');
            var invoicePrice = $('#item26_text_1');

            $(invoicePrice).val("");
            $(monthlyRate).val("");
            $(rooms).val("");
        }

        // ------------------------------------ function update() ------------------------------------
        //
        // This function accepts the per-invoice rate, monthly rate, number of rooms, and updates the 
        // read-only fields on the form.

        function update(result) {

            var rooms = $('#item21_text_1');
            var monthlyRate = $('#item23_text_1');
            var invoicePrice = $('#item26_text_1');

            $(invoicePrice).val('$' + result.invoicePrice);
            $(monthlyRate).val('$' + result.monthlyRate + ' per room');
            $(rooms).val(result.numberOfRooms);
        }


        // ------------------------------------ function prereqsToCompute() ------------------------------------
        //
        // This function verifies that:
        //      - a region has been selected
        //      - the number of rooms has been provided
        //      - the number of rooms provided is numeric
        // and returns 'TRUE' or 'FALSE"

        function prereqsToCompute() {

            var select_your_region = $('#item7_select_1');
            var specified_number_of_rooms = $('#item9_text_1');

            if (select_your_region.val() &gt; 0 &amp;&amp; $.isNumeric(specified_number_of_rooms.val()) &amp;&amp; specified_number_of_rooms.val() != "") {
                return true;
            } else {
                return false;
            }
        }

        // ------------------------------------ function compute() ------------------------------------

        // This function computes the monthly invoice price and returns it.
        // This function will only execute if prereqsToCompute() returns 'TRUE'

        function compute() {

            var specified_number_of_rooms = $('#item9_text_1');
            var select_your_region = $('#item7_select_1');
            var billing_terms = $('#item27_select_1').val();
            var multiplier = 0;

            // The decision tree below determines the multiple by which to multiply times the total monthy rate (number_of_rooms * price_per_room)
            // If quarterly is selected, multiply by 3.
            // If semiannual is selected, multiply by 6.
            // If annual is selected, multply by 12.

            if (billing_terms == 1) {
                multiplier = 3;
            } else if (billing_terms == .98) {
                multiplier = 6;
            } else {
                multiplier = 12;
            }

            // compute invoicePrice (number_of_rooms * price_per_room * multiplier * billing terms (discount) and
            // compute monthlyPrice (number_of_rooms * price_per_room * billing terms (discount)
            // and return those values

            var monthlyRate = select_your_region.val()

            var numberOfRooms = specified_number_of_rooms.val();


            var monthlyPrice = (numberOfRooms * monthlyRate * billing_terms).toFixed(2)

            // $60 monthly minumum required for service

            if (monthlyPrice &lt; 60) {
                monthlyPrice = (60.00).toFixed(2);
           }

            var invoicePrice = (monthlyPrice * multiplier).toFixed(2);

            return {
                invoicePrice: invoicePrice,
                monthlyPrice: monthlyPrice,
                monthlyRate: monthlyRate,
                numberOfRooms: numberOfRooms
            };
        }


    });


&lt;/script&gt;
</code></pre>
