Hello Everyone!

This is my first post, so please excuse me for any breaches of netiquette.

I am building my own from validation script, which uses separate functions for each input box like so.

<input type="text" name="username" onchange="CheckUsername(this.value);">

A bit of javascript sends this along to a php file using the $_GET variable without reloading the page. The php file checks the username against my database and the result will be printed beside the input box. The javascript is this:

var xmlHttp 

function GetXmlHttpObject(){ 
var objXMLHttp=null 
if (window.XMLHttpRequest){ 
objXMLHttp=new XMLHttpRequest() 
}else if (window.ActiveXObject){ 
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP") 
} 
return objXMLHttp 
} 

function CheckUsername(username){ 
xmlHttp=GetXmlHttpObject() 
if (xmlHttp==null){ 
alert ("Browser does not support HTTP Request") 
return 
} 
var url="check.php?username="+username 
xmlHttp.open("GET",url,true) 
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) { 
document.getElementById("usernameresult").innerHTML = xmlHttp.responseText;
} 
}; 
xmlHttp.send(null);
}

This works fine for single values, I also have a different bit of code for checking emails to be valid and so on.

However I ran into a problem with password checking. I can check if the password is too short by sending the first password field off to the script. However I can't send two fields at once (password and password check) to see if the passwords entered match.

Can anyone give me some tips on how to modify my script to accomodate for two variables like that? By the way I'm actually not really good at javascript, I found most of this code on the net, and modified it as I went along by trial and error, so please try and go easy on me :)

Thanks a lot everyone!

Recommended Answers

All 2 Replies

try this:

var url="check.php"
url=url+"?password="+password 
url=url+"?password_check="+password_check

Thanks for the tip!
It didn't solve my problem, but I started thinking. In the end, I modified my onchange and my script itself.

the answer was to modify the onchange to facilitate two arguments, and then to pass both in a $_GET much the was you did it, although it can be done on one line using the plus sings.

Thanks for getting me thinking!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.