0

I need to pass in form variables via AJAX every time a select box value is changed, and get a returned string from the AJAX call to display on the page. Here's the situation:

I built a form which is dynamically built by the user for a set of compliance rules. This allows the user to have multiple select boxes to generate a logic statement such as the following:

(
  ( 6779 AND 10852 AND 10845 )
  AND 
  (
    ( 8260 AND 8258 ) 
  )
)
OR
( 6780 OR 10845 OR 8258 OR 12893 )

I've written a function that returns this logic statement as a string after submission of the form, but would like to dynamically populate a div (#logicblock) on the form page BEFORE submitting, so that the user can verify the logic before submission of the information into our database.

I tried to use the following:

 ('##logicblock').load("#getmodel('model.compliance').BuildLogic(rc)#", function(response){
     $('##logicblock').html(response);
 })

... but this does not properly pass in the RC scope into my model. I've searched and can't find a way that makes sense to me to send the entire form scope into a method that returns a value for display on the page.

D PEN
  • 1
  • 2

1 Answers1

0

I got it figured out. Because the form fields are dynamically generated, I found that I couldn't use a $('select').change() event to call the method, so I wrote a handler method to generate the data and serialized the form to pass in to the handler. I was able to use the following to get the desired response:

function updateLogicBlock(){
    var serialform = $('form').serialize();
    $.get("#event.buildLink('handler.buildComplianceLogic')#?" + serialform, 
      function(data) {
        $('##logicblock').html(data);
    });
};

Then I simply added onChange="updateLogicBlock();" to every select box on the form.

D PEN
  • 1
  • 2