README.md

December 4, 2022 ยท View on GitHub

Validate an HTML form control against a database without submission

Description

I was fed up with entering a username on various websites, posting the form only for it to return with a server posted message that the username was already in use. This function will alert the user if the value he had entered was found to be already existing without the form being submitted. Later flavours of I.E. only

More Info

Assumes that the user can create the simple ASP that does the Database lookup on the text that was entered.

Only supported by I.E 5 +

Submitted On
BySimon Goodwin
LevelIntermediate
User Rating5.0 (10 globes from 2 users)
Compatibility
CategoryForms Validation Processing
WorldJava
Archive File

Source Code

// <!-- script for the header/js file --> //
function validateuserid(item,suserid)
{
	document.body.style.cursor='wait';
	// Create an instance of the XML HTTP Request object
	var oXMLHTTP = new ActiveXObject( "Microsoft.XMLHTTP" );
	// Prepare the XMLHTTP object for a HTTP POST to our validation ASP page
	// enter the path to your validation ASP[X]
	var sURL = "http://yourdomain/yourvalidatingpage.asp?userID=" + suserid
	oXMLHTTP.open( "GET", sURL, false );
	// Execute the request
	oXMLHTTP.send();
	if (oXMLHTTP.responseText == "exists") // if the ASP response.writes the string "exists" then
	{
		alert("Sorry - the User ID\n " + suserid + "\nalready exists!");
		item.value="";
		item.focus();
	}
	document.body.style.cursor='auto';
}
// <!-- HTML form control to validate --> //
<INPU[T] type=text maxLength=30 size=30 value="" name="username" class=TextBox onblur="validateuserid(this,this.value);">