Jump to content

Using Multiple Scripts on One Form


chocopi

Recommended Posts

I use the following script for my username validation and I would like to use the same script for my password field, however when I tried changing the code it would only run the validation for the password and not the username

 

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<title>
		Ajax
	</title>
<meta http-equiv="Content-Type" content="text/javascript; charset=iso-8859-1">
<script language="javascript"  type="text/javascript">

var url = "signup.php?username="; // The server-side script

function updateName() {
  // display a quick message while the script is being processed
  document.getElementById('un').innerHTML = "<img src=waiting.gif>";
  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>
<body>
<br />
<br />
<br />
<center>
<form method="post" action="<?php echo $PHP_SELF; ?>" name="ajax" id="ajax">
<table width="100%" border="0">
<tr>
	<td align="right" width="50%">
		Username <input type="text" name="username" onblur="updateName();" id="username" value="<?php echo $username; ?>" maxlength="20"/>
	</td>
	<td align="left" width="50%">
		<div  name="un" id="un"></div>
	</td>
</tr>
<tr>
	<td align="right" width="50%">
		Password <input type="password" name="password" onblur="" id="password" value="" maxlength="20" />
	</td>
	<td align="left" width="50%">
		<div  name="pwd" id="pwd"></div>
	</td>
</tr>
<tr>
	<td align="center" width="100%" colspan="2">
		<input type="submit" name="submit"/>
	</td>
</tr>
</table>
</form>
</body>
</html>

 

So what I'm asking is, how can I make it so I can validate my password aswell as my username with the above script.

 

Many Thanks,

 

~ Chocopi

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.