Ah!  Some helpful individual here in Philadelphia posted a clue for me
on the PANMA list and I've evolved his suggestion into this code which
works like magic:

function edit_event_handlers( ) {
         // highlight the field backgrounds when the user enters it
   for ( var target in datafields ) {
      $(datafields[target]).focus( function(dt,ft) {
         return function() {
            $(dt).css('background-color','#FDD') ;
            $(ft).css('background-color','#FDD') ;
         }  ;
      }(datafields[target], fieldfields[target]) ) ;
         // restore the field backgrounds when the user exits it
      $(datafields[target]).blur( function(dt,ft) {
         return function() {
            $(dt).css('background-color','#EFE') ;
            $(ft).css('background-color','#EFE') ;
         }  ;
      }(datafields[target], fieldfields[target]) ) ;
         // Set the handler for the onChange event
      $(datafields[target]).change(function(event) {
         dft = "#" + this.id ;
         $(this).css('background-color', 'orange');
         fft = "#" + this.id.replace('data','field')  ;
         $(fft).css('background-color', 'orange');
         $.post("/index.php/Workflow_server/updatefield/",
            {"fieldname": mapping[this.id], "fieldval": $(this).val
()},
               function() {
                  $(dft).css('background-color', '#AAF' ) ;
                  $(fft).css('background-color', '#AAF' ) ;
               }
           );
        });
    } ;
}

The data arrays are missing from this code snippet but the key was
understanding that closures were not needed - I can just use "this"
which jQuery sets for me.

Still learnin'... this is great!

Eric

Reply via email to