views:

1811

answers:

2

This is in reference to jQuery 1.3 and jQuery Form Plug 2.25.

Hopefully this is a cakewalk for even an amateur, but I am clueless.

var x;
$('div#response').fadeOut(300,function()
{
   // do something
   x = this;
}
$('#myForm').ajaxForm({ 
    target: x,
    success: function() 
      { 
        // do something
      }
});

What I'd like to do is define the target value as a variable I have pre-defined; we'll say it is "x". This is shown in the example above but the line "target: x," of course fails. How can I do this?

Additionally: I am aware that x = div#response in this example, but in the real world problem I am working on, I don't have a solid definition of x. I know in this example I could just change "target: x," to "target: div#response," and it'd work but this example is merely for argument. I need target to equal x. How do I do that?

+1  A: 

Assuming your ajax call returns plain text, this should work: (You can remove the target option if you want, the variable x will be set either way.)

$('#myForm').ajaxForm({
  target: $('#someDiv'),
  success: function(response) {
    x = response;
  }
});
brianpeiris
That looks like it is redefining the response; I need to redefine the target.
Chris Cooper
A: 

Assuming x is a jquery wrapped set, something like this should work:

$('#myForm').ajaxForm({
  success: function(responseText, statusText) {
    x.html(responseText);
  }
});
Steve Willcock
Brilliant! Simple and effective. I knew it'd be something basic I just didn't think of.
Chris Cooper