Jump to content

registration form


chriscloyd

Recommended Posts

okay i have looked on some websites as the person is filling out the registration form it checks it automaticaly as they r finished. like they fill out the username textbox and as soon as they move on it checks the password and shows if its avaible or not right next to the text box can anyone tell me how to do that?
Link to comment
https://forums.phpfreaks.com/topic/16522-registration-form/
Share on other sites

<script language="javascript"  type="text/javascript">

var url = "register.php?param="; // The server-side script

function updateName() {
  // display a quick message while the script is being processed
  document.getElementById('un').innerHTML = "...checking database...";
  var name = document.getElementById("username").value;
  http.open("GET", url + escape(name), true);
  http.onreadystatechange = handleHttpResponse;
  http.send(null);
}

function handleHttpResponse() {
  if (http.readyState == 4) {
    results = http.responseText;
    var name = document.getElementById("username").value;
    if(results == "") results = "Username <i>"+name+"</i> Is Available...";
    // the div in which the message appears
    document.getElementById('un').innerHTML = results;
  }
}

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP Object
</script>
</head>


The form is as follows.

<form method="post" action="signup.php" name="theForm" id="theForm">
Desired Username:<br/>
<input type="text" name="username" onblur="updateName();" id="username"/>
<div style="background: #eee;" name="un" id="un"></div>
<input type="submit" name="submit"/>
</form>

The text input field calls javascript function 'updateName()' when the user removes focus on the input field.

The script returns the resulting message into the div with id 'un'

<?php
include('DB_Connect.php');
$connect = new DB_Connect2();
$u = addslashes($param);

// change to reflect your database info
$sql = "select userName from user where userName = \"$u\"";
$r = $connect->query_db($sql);
while ($row = mysql_fetch_array ($r)) {
    $un = $row['userName'];
}
if($u == $un) echo "<font color=\"red\">Username $u already in use</font>";
?>
Link to comment
https://forums.phpfreaks.com/topic/16522-registration-form/#findComment-69028
Share on other sites

  • 2 weeks later...
Hi,

I'm the owner of shawngo.com

The script you're talking about here is fairly ugly. I've really been meaning to clean up my code and stuff.

If you'd like, I can post a really simple version of this.

Using prototype.js and behaviour.js makes javascript life SUPER easy!! :D

I highly recommend both of these scripts, as well as several other javascript toolkits (scriptaculous, moo.fx, dojo, etc)

My email is shawn at shawngo dot com ( or anything at shawngo dot com for that matter ;;)

Shawn
Link to comment
https://forums.phpfreaks.com/topic/16522-registration-form/#findComment-73916
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.