|
-
Feb 6th, 2010, 09:49 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] check if variables match?
i need to check if the contents of 2 textboxes match and i load the contents of these 2 into a variable
Code:
var pass = document.getElementById('password').value;
var cpass = document.getElementById('cpassword').value;
correct the code if its wrong, because i'm kinda new at javascript, my friend told me to stay away from it if it was possible xD
so what i need to do is check if those 2 textboxes value match, how to do this?
-
Feb 6th, 2010, 11:54 AM
#2
Re: check if variables match?
Code:
if(pass == cpass){
alert('they match.');
}
-
Feb 6th, 2010, 11:57 AM
#3
Re: check if variables match?
Just a more verbose example 
Code:
window.onload = function(){
document.getElementById("myForm").onsubmit = function (){
var pass = document.getElementById('password').value;
var cpass = document.getElementById('cpassword').value;
if(pass == cpass){
alert("They're the same!");
}else{
alert("They're not the same.");
}
return false;
}
}
This assumes that you've given your form an id of "myForm", and that you want the comparison to be done when the person submits the form. You would need to alter this code because it always returns false to the form (so it will never submit).
-
Feb 6th, 2010, 12:14 PM
#4
Thread Starter
Fanatic Member
Re: check if variables match?
thanks Kows and Samba i only needed the code for checking, the rest i would like to do my self, and so i did:
Code:
function checkpassword() {
var pass = document.getElementById('password').value;
var cpass = document.getElementById('cpassword').value;
if(pass == cpass){
document.getElementById('passresult').innerHTML = "Passwords match";
} else {
document.getElementById('passresult').innerHTML = "Passwords do not match";
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|