tags:

views:

18

answers:

1

Hi,

thanks for looking.

I'm having an issue i cant seem to get the submit function workin.

load login form if needed.

login_box_comment = function(){
 $("body").append('<div id="login_form_modal" style="display:none">'+
'<div id="status" align="left">'+
'<center><h1><img src="/ext/login/img/key.png" align="absmiddle">&nbsp;LOGIN</h1>'+
'<div id="login_response"><!-- spanner --></div> </center>'+
'<form id="login" action="javascript:alert(\"success!\");">'+
'<input type="hidden" name="action" value="user_login">'+
'<input type="hidden" name="module" value="login">'+
'<label>Username</label><input type="text" name="user"><br />'+
'<label>Password</label><input type="password" name="password"><br />'+
'<input type="checkbox" name="autologin" id="autologin" value="1">Log me on automatically each visit<br />'+
'<input type="checkbox" name="viewonline" id="viewonline" value="0">Hide my online status this session<br />'+
'<label><a href="/forum/ucp.php?mode=register">Register</a> | </label><input value="Login" name="Login" id="submit" class="big" type="submit" />'+
'<div id="ajax_loading">'+
'<img align="absmiddle" src="/ext/login/img/spinner.gif">&nbsp;Processing...'+
'</div>'+
'</form>'+
'</div>'+
'</div>');

$('#login_form_modal').modal();
}

and ths submit function

$("#status > form").submit(function(){  
alert('working');
}):
+1  A: 

You need to attach the submit handler only after the form has been appended to the DOM. So, you need to first make sure the login_box_comment function is called and only then attach the event because if the form is not present in the DOM the jQuery won't do anything:

login_box_comment();
$('#status > form').submit(function() {
    alert('working');
});

or simply attach the submit handler inside the login_box_comment function:

login_box_comment = function() {
    $('body').append('.......');
    $('#status > form').submit(function() {
        alert('working');
    });
    $('#login_form_modal').modal();
};
Darin Dimitrov
im really new to this so im going to research on "Adding elements to the DOM"
jay
any chance of an example on how to do that?
jay
Look at my second code snippet. You `.append` elements to the DOM and then you attach event handlers to them (`.submit`).
Darin Dimitrov