javascript - JQuery not running from PHP echo -
i trying execute simple jquery commands in echo statement php after user submits log in form.
the user able log in correct credentials, if enter incorrect ones should show invalid credentials paragraph.
here code:
<?php //php code login in, working, not needed show echo 'testing <script> $( ".wrong" ).show( "slow" ); </script>'; ?> <!doctype html> <html> <head> <script src="//code.jquery.com/jquery-1.10.2.js"></script> </head> <body class="login"> <form action="" method="post" class="login-form"> <p class="wrong" style="display: none;">invalid credentials</p> <a class="link" href="#">forgot password?</a> <button type="submit" class="login-btn" name="submitlogin">log in</button> </form> </body>
note: testing value echo displays, yet jquery not execute.
it not possible put php code after html creates session login form work.
<?php echo 'testing <script> $( ".wrong" ).show( "slow" ); </script>'; ?>
this not create session, , not need @ top. needs @ top session_start()
call yes, echoing out script html not required @ top
for instance
<?php session_start(); if(attemptlogin()){ //logged in path } else { //wrong credentials $loginerror = true; } ?> <!doctype html> <html> <head> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <?php if($loginerror):?> <script> jquery(document).ready(function(){ $( ".wrong" ).show( "slow" ); }); </script>; <?php endif;?> </head>
Comments
Post a Comment