Bottom line: do self = this at top of the submit function, then use self for context.
-- Yehuda
On 10/28/06, Julius Lucks <
[EMAIL PROTECTED]> wrote:
Hi All,
I am using a $.post to enter some data in the db, and using the callback function to set some html on the screen based on the html that the post returned. I have the following code:
$("div.input form").submit(function() {
/*get form vars here to form params_hash*/
$.post("url",{params_hash_here}, function(html) {
var new_var = parsing_the_response_html_here_correctly;
$("[EMAIL PROTECTED]",this).html(new_var);
});
});
However, the second piece of code that alters the screen html applies to the whole screen (effectively ignoring 'this' context), and not to the 'this' context that the post was part of. (Basically there are multiple submit buttons on the page and I want to post data from only one of them - the one who's submit button I clicked.)
I also tried the following modification, thinking that I could get around the problem with variable scoping
$("div.input form").submit(function() {
/*get form vars here to form params_hash*/
/*now I am initializing new_var before the post*/
var new_var = '';
$.post("url",{params_hash_here}, function(html) {
new_var = parsing_the_response_html_here_correctly;
});
$("[EMAIL PROTECTED]",this).html(new_var);
});
So I define new_var before the post, use the callback function to set its value, and then use the html changing element in the code block that I know 'this' works for. This solution did not work at all and caused some weird hangups.
Basically this boils down to my misunderstanding of variable scope, in particular the scope of 'this' in jquery. Any help is much appreciated!!!
Julius
--
-----------------------------------------------------
http://openwetware.org/wiki/User:Lucks
-----------------------------------------------------
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/
--
Yehuda Katz
Web Developer | Wycats Designs
(ph) 718.877.1325
_______________________________________________ jQuery mailing list [email protected] http://jquery.com/discuss/
