fry2010 Posted April 24, 2009 Share Posted April 24, 2009 Can someone help. I have found this tutorial on checking username input, but I cannot get it to work. Iv looked at so many tutorials but just 'dont get it'. http://www.ebrueggeman.com/blog/ajax/php-ajax-username-example/php_ajax_framework.js Why is it the tutorial doesnt just go through steps such as: step 1: do this, you will need this etc.. step 2: now do this .... etc... Instead its jumbled up and doesnt even work when I use everything. Ok so what I have is the main php_javascript_framework.js file. I have this in my main php page: <?php $username = trim($_GET['username']); if (usernameExists($username)) { echo '<span style="color:red";>Username Taken</span>'; } else { echo '<span style="color:green;">Username Available</span>'; } function usernameExists($input) { // in production use we would look up the username in // our database, but for this example, we'll just check // to see if its in an array of preset usernames. $name_array = array ('steve', 'jon', 'george', 'admin'); if (in_array($input, $name_array)) { return true; } else { return false; } } ?> <html> <head> <link href="http://www.ebrueggeman.com/includes/styles.css" rel="stylesheet" type="text/css" media="all" /> <style type="text/css"> div{ margin-left:0; text-align:left; } </style> <script type="text/javascript" src="php_ajax_framework.js"></script> <script type="text/javascript"> function check_username_init() { var user_field = document.getElementById('user'); return 'username_exists.php?username=' + user_field.value; } function check_username_ajax(results) { var results_div = document.getElementById('results_div'); results_div.innerHTML = results; } function check_username() { var user_field = document.getElementById('user'); if (user_field.value.length > 0) { //call our AJAX function in the PHP AJAX Framework ajaxHelper('check_username'); } else { //clear results field var results_div = document.getElementById('results_div'); results_div.innerHTML = ''; } } </script> </head> <body> Username: <input name="user" id="user" size="20" onKeyUp="check_username();"> <div id="results_div"></div> </body> </html> What happens is it just comes up with: username available! and doesnt change at all. Even when I put in names like 'steve', 'jon' which should cause it to say: not available! Any help appreciated, this is incredibly annoying how no tutorials are not clear. I dont really want to learn javascript I just want this function. Thanks. Link to comment https://forums.phpfreaks.com/topic/155527-username-check-problem/ Share on other sites More sharing options...
fry2010 Posted April 25, 2009 Author Share Posted April 25, 2009 i sorted this out yesterday. But now I want to check the password as well. The username check is working, so I copied basically everything I used for the username but made it for the password and the password doesnt work. I have tried to seperate the files that call the php response to two seperate files : check_username.php check_password.php any ideas on what im doing wrong? Link to comment https://forums.phpfreaks.com/topic/155527-username-check-problem/#findComment-819069 Share on other sites More sharing options...
fry2010 Posted April 25, 2009 Author Share Posted April 25, 2009 ok solved that last one aswell. Iv just realised I actually hate javascript... Link to comment https://forums.phpfreaks.com/topic/155527-username-check-problem/#findComment-819114 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.