views:

83

answers:

1

I am using jQueryUI dialog to open a modal form on my site. The form has a hidden input to pass on an affiliate code that is passed in the query string, like

http://mydomain.com/page1_with_form?affiliate=Chuck%20Norris

http://mydomain.com/page2_with_form?affiliate=Chuck%20Berry

I am using a jQuery plugin to make grabbing the GET values easy.

Both of the 2 pages (page1_with_form and page2_with_form) load the same modal form my_affiliate_form.html in a dialog box. I have no problem doing something like this on the my_affiliate_form.html page

var affiliate_code = $.query.get('affiliate');
if (!affiliate_code) affiliate_code = "None";
$('[name=hidden_affiliate_field]').val(affiliate_code);

This works just dandy, and my affiliate ends up being Chuck Norris and Chuck Berry.

The problem, is now I want to not only include the affiliate code from the query string, but also want to use a key that is representative of the page they loaded the form from, ie. page1_with_form and page2_with_form). For page1, the key might be "Public" and for page2 maybe "Private", or something like that.

Now I want it where my hidden field has a value of "Public Chuck Norris" when hitting this page http://mydomain.com/page1_with_form?affiliate=Chuck%20Norris and "Private Chuck Norris" when hitting this page http://mydomain.com/page2_with_form?affiliate=Chuck%20Norris

I am loading the dialog contents like this:

$('#modal-form-holder').dialog({
          bgiframe:true,
          width:width,
          title: title,
          modal:true,
          resizable: false,
          closeOnEscape: true,
          draggable: false,
          autoOpen:false
 }).load("my_affiliate_form.html?affiliate_key=" + key, null, onComplete);

The value for key is getting filled in correctly, but if my_affiliate_form.html tries to grab the "affiliate_key" via $.query.get('affiliate_key') it is empty. This is because the query plugin in inspecting window.location, which hasn't changed.

How can I grab the request paraemeter in my_affiliate_form.html that came in the ajax request?

Sorry for being so verbose, I just want to make my question as clear as possible.

A: 

Set the value in your onComplete handler. Something like:

$('#modal-form-holder').dialog({
          bgiframe:true,
          width:width,
          title: title,
          modal:true,
          resizable: false,
          closeOnEscape: true,
          draggable: false,
          autoOpen:false
 }).load("my_affiliate_form.html", null, function(responseText, textStatus, XMLHttpRequest)
{
  onComplete(responseText, textStatus, XMLHttpRequest, key);
});

Then, in onComplete (which should be defined to take all four parameters), fill the affiliate_key field with key.

Matthew Flaschen
Ok, the code for creating the dialog is inside another function. One of the paramaters for that function is the callback, named onComplete. So when I call this I do, `addModalForm(600, 200, "SomeTitle", url, onThisRequestComplete);` The my_affiliate_form.html is not hard coded in the load, but instead uses the param for url. Do I have to use an anonymous function, or can I still do it my way?
sberry2A