In ExtJS, Can I call a for loop and an if statement inside an Ajax request to define my parameters?

2.1k Views Asked by At

I am trying to iterate through my checkboxes that are in a fieldSet and if the checkbox is checked, I would like to add the id of the checkbox to an array that would be one of my parameters for my Ajax request.

I realize that I could have created a Checkbox group, but I am new to ExtJS and didn't find out about Checkboxgroup until after I created each individual checkbox.

So far I have this..

    function submitEntry(){
        Ext.Ajax.request({
                         url: '../../inc/project4.php',
                                var obj = Ext.select('input[type=checkbox]').elements;
                                var i = 0;
                        for (i=0; i<obj.length; i++) {
                            if (obj[i].checked) {
                                params:{
                                    symptom[]: obj[i].getId()
                                    }
                                }
                            }
                             params: {action: 'create_input',
                                description: entryBox.getRawValue(),
                         },
                                    method: 'POST',
                        success: function(f,a){
                            var jsonData = Ext.util.JSON.decode(f.responseText);
                            if(jsonData.success == true){
                                Ext.Msg.alert("Success!", "Your journal entry has been sent!");
                                entryStore.reload();
                                entryBox.reset();
                            }
                            else{
                                Ext.Msg.alert("Error! Please check your entry and try again.")
                            }
                        },
                        failure: function(f,a){
                            if(jsonData.success == false){
                                Ext.Msg.alert("Error! Please check your entry and try again.");
                            }
                        }
                         });
    }

Please pick and point out any errors. I am unsure if the way I have two sections for params will even work. I just need to add the id's of the checked checkboxes to the array and send that array as one of my parameters.

Thank you very much in advance for any help!

1

There are 1 best solutions below

0
On

If you need more than one expression to collect your checkboxes, you should collect them before the call to Ext.Ajax.request.

var checkboxes = Ext.select(...);
// do other stuff to get just the checkboxes you want

Ext.Ajax.request({
   url: "...",
   params: checkboxes,
   ...
});