views:

90

answers:

1

Uaing the Prototype JavaScript library, I have this

var panelItemId = 12345;

var param1 = 'expandPanel';    

var updater = new Ajax.Updater('myTarget','myUrl',{
        method: 'get',
        parameters: {
        expandPanel: panelItemId

        }
      } 
     );

I want to replace expandPanel in the parameters object with the variable param1, because in some cases I wish the parameter to be 'collapsePanel'. The panelItemId is evaluated as a variable, but expandPanel is taken to be a string. I would like to replace it with the value of param1. If I just type param1 instead of expandPanel then the first parameter passed will be named param1 instead of being named expandPanel.

I know that I could achieve this by building a querystring and using that as the parameters argument. I would prefer to use the object notation, as above.

A: 
var panelItemId = 12345;
var param1 = 'expandPanel';    
var obj = {};
obj[param1] = panelItemId;
var updater = new Ajax.Updater('myTarget','myUrl',{
  method: 'get',
  parameters: obj
});
Marius