PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

javascript onchange

  1. twofus
    Member

    I'd like to be able to add data to the field input line so that this:

    <input name='input_95' id='input_2_95' type='text' value='' class='small' tabindex='37' />

    becomes this:

    <input name='input_95' id='input_2_95' type='text' value='' class='small' tabindex='37' onChange="CalculateTotal(this.form)" />

    but only on specific fields.

    The idea is populate a field using javascript:
    http://www.mcfedries.com/javascript/ordertotals.asp

    Any Ideas?

    BTW, if anyone is curious, I was able to get After the Deadline spell checker (jquery) to work with multiple textareas.. one click checks the entire form's input and allows the writer to modify before saving the form.

    Posted 13 years ago on Saturday December 4, 2010 | Permalink
  2. what you want to do is use jQuery to bind to the field's onchange event.
    Something like

    jQuery(document).ready(function(){
       jQuery('#input_2_95').bind('onchange', function (){
          CalculateTotal(this.form);
       });
    });
    Posted 13 years ago on Saturday December 4, 2010 | Permalink
  3. twofus
    Member

    for those wondering, here's a piece of code I used to make this work:

    http://www.pastie.org/1357423

    <script type="text/javascript">
    
    jQuery(document).ready(function() {
       var values = $('#input_2_86,#input_2_129,#input_2_95,#input_2_96').change(function() {
       var sum = 0;
       values.each(function() { // Step through each one
       var value = parseInt($(this).val(), 10); // Retrieve its numeric value
       sum += (isNaN(value) ? 0 : value); // Add to the total
       });
      $('#input_2_88').val(sum / 4); // And show the average
      });
    });
    </script>
    Posted 13 years ago on Wednesday December 8, 2010 | Permalink

This topic has been resolved and has been closed to new replies.