sniperscope Posted July 12, 2011 Share Posted July 12, 2011 Hello I want to make some login panel with ajax but have no idea where to start. Please let me explain a little what i want to do. When a user type his login name i want to send(onblur()) typed value to db.php and returning value assign to a javascript valiable. My login.php is: <form name="loginform" id="loginform" method="post" action=""> <table width="300px" class="login" cellpadding="5" cellspacing="2" style="margin:auto;"> <tr><td align="left" colspan="2"> </td></tr> <tr class="row2"><td class="login_lines">username</td> <td class="login_lines"><input id="user" type="text" name="user" size="20" onBlur="GotoAjax();" /></td></tr> <tr><td class="login_lines">password</td> <td class="login_lines"><input id="pass" type="password" name="pass" size="20" /></td></tr> <tr><td colspan="2" style="text-align: center"><input type="submit" value="login" class="input-button" /></td></tr> </table> </form> And db.php is: <?php include('../inc/cn.php'); $SQL = mysql_query("SELECT * FROM users WHERE username = '" .$_POST['user']. "'"); $ROW = mysql_fetch_array($SQL); ?> i want to assign $ROW data into a javascript variable something like this : login.php <script language="text/javascript"> function GotoAjax(){ // AJAX MAY RUN HERE. } var id = <?php echo $ROW['id']; ?>; // Return Value from Ajax query var username = <?php echo $ROW['username']; ?>; // Return Value from Ajax query var mail = <?php echo $ROW['mail']; ?>; // Return Value from Ajax query ... ... ... so on </script> How can i make this? Regards Quote Link to comment https://forums.phpfreaks.com/topic/241760-return-value-to-valiable/ Share on other sites More sharing options...
sniperscope Posted July 12, 2011 Author Share Posted July 12, 2011 Okay i solved my problem something like this. I hope this solution saves someones hours. Regards login.php : <html> <head> <script type="text/javascript"> var servername = ""; function showUser(str) { if (str=="") { return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { servername = xmlhttp.responseText; } } xmlhttp.open("GET","check.php?domain="+str,true); xmlhttp.send(); } function craftAction() { document.getElementById("errorspace").innerHTML = ''; var launch = 1; var output = false; if(document.loginform.domain.value == '') { document.getElementById("errorspace").innerHTML += '<font color=#FF0000><?php echo $LOGIN['error1']; ?></font><br />'; launch = 0; } if(document.loginform.pass.value == '') { document.getElementById("errorspace").innerHTML += '<font color=#FF0000><?php echo $LOGIN['error3']; ?></font><br />'; launch = 0; } if(document.loginform.user.value == '') { document.getElementById("errorspace").innerHTML += '<font color=#FF0000><?php echo $LOGIN['error2']; ?></font><br />'; launch = 0; } if(launch == 0) { output = false; } else{ var port = document.loginform.port.value; var theaction = "https://" + servername + ".winhostings.com:2083/login/" document.loginform.action = theaction; output = true; } return output; } </script> </head> <body> <form name="loginform" id="loginform" method="post" action=""> <table width="300px" class="login" cellpadding="5" cellspacing="2" style="margin:auto;"> <tr><td align="left" colspan="2"> </td></tr> <tr class="row2"><td class="login_lines">username</td> <td class="login_lines"><input id="user" type="text" name="user" size="20" onBlur="showUser(this.value);" /></td></tr> <tr><td class="login_lines">password</td> <td class="login_lines"><input id="pass" type="password" name="pass" size="20" /></td></tr> <tr><td colspan="2" style="text-align: center"><input type="submit" value="login" class="input-button" /></td></tr> </table> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/241760-return-value-to-valiable/#findComment-1241670 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.