On the login page of my site I have two identical login forms. One is in the main body of the page and the 2nd one is loaded into a jquery dialog for the Login link in the header. I have already removed all identical ID's and used class instead.
What I am trying to do is: after user clicks submit in the dialog, I am trying to put the error msg in the right DIV but I get undefined for $(this)
after the jquery post()
or ajax call.
$('.login-submit').live('click', function(){
alert($(this).attr('class')); // THIS WORKS
var form = $(this).parent('form').get(0);
var values = $(this).parent('form').serialize();
$.post('/users/login',values,function(data){
if(!data['success']) {
alert($(this).attr('class')); // THIS SAYS UNDEFINED
// TRYING TO DO THIS
$(this).siblings('.form-error').html(data['error']);
}
},'json');
});
Here is the HTML:
<form class="form-login" method="post" action="/users/login">
<input type="hidden" name="_method" value="POST">
<div class="form-error"></div>
<input name="data[User][username]" type="text" maxlength="20" id="UserUsername">
<input type="button" class="login-submit" value="Sign In">
</form>