0

Hi all, I've been trying to implement the onblur function for a database, but i'm having trouble getting it to work. It's suppoed to be used for my 2nd password field to check it.

Would anyone be able to help me implement into the following code I have?:

script type="text/javascript">
function clear2(pass) 
{
    var x = document.getElementById(pass);
    x.value = "";
}
<!--I used pwdCheck because it will make sure that the values are correctly input, or that there is no missing field so that the database will not have an empty row if customer forgets to put one-->
function pwdCheck1()
{
    pwd1 = document.getElementById('password1').value;
    pwd2 = document.getElementById('password2').value;
    name = document.getElementById('name').value;
    email = document.getElementById('email').value;

    if(pwd1 == pwd2 && pwd1!="" && pwd2!="" && name!="" && email!="")
    {

        document.getElementById("checkpwdForm1").style.display = 'none';
        document.form1.submit();
        return true;
    }
    else
    {
        clear2('password1');
        clear2('password2');
        document.getElementById("checkpwdForm1").style.display = 'block';
        return false;
    }
}

function pwdCheck2()
{
    xpwd1 = document.getElementById('xpassword1').value;
    xpwd2 = document.getElementById('xpassword2').value;
    xname = document.getElementById('xname').value;
    xemail = document.getElementById('xemail').value;
    xaddress = document.getElementById('xaddress').value;
    <!---checks to see if passwords are equal and if all fields are filled in--->
    if(xpwd1 == xpwd2 && xpwd1!="" && xpwd2!="" && xname!="" && xemail!="" && xaddress!="")
    {

        document.getElementById("checkpwdForm2").style.display = 'none';
        document.form2.submit();
        return true;
    }
    else
    {
        clear2('xpassword1')
        clear2('xpassword2')
        document.getElementById("checkpwdForm2").style.display = 'block';
        return false;
    }
}
</script>
2
Contributors
3
Replies
15
Views
4 Years
Discussion Span
Last Post by LastMitch
0

Would anyone be able to help me implement into the following code I have?:

Does it work for the 1st password? Why you modify the code like that? It should be one password for one function.

Meaning

function#1 has password 1
function#2 has password 2

The reason is if you have 2 passwords in each function then your have 2 column of 2 different passwords.

I'm bit curious how your query will select the 2 passwords from your database at the same time?

If you query doesn't work then your onblur function wouldn't work either

You never provide the query only the variables in your javascript.

What language are you using PHP or ASP.net or some other?

Edited by LastMitch: grammer

0

Using PHP, the pass2 is just another field for checking pass1, it's what the professor wanted, he actually wants us to code it inside an HTML form, using javascript. I don't understand why, being HTML5 already supports the blurring

0

Using PHP, the pass2 is just another field for checking pass1,

So does it work (meaning the password code does it work for 1 password without the pass)?

You should also post the form with it because it's not very clear on how this works.

Here is a simple example on how the onblur function works:

This is base on the variables you are usings this is just HTML:

<script type="text/javascript">

function Username() {
var pId = document.getElementById("UserId").value;
if (pId.length == 0) {
alert("User Id should not be empty");
}
}

function pwdCheck1() {
var oPassword1 = document.getElementById("Password1").value;
if (oPassword1.length == 0) {
alert("User Password1 should not be empty");
}
}


function pwdCheck2() {
var oPassword2 = document.getElementById("Password2").value;
if (oPassword2.length == 0) {
alert("User Password2 should not be empty");
}
}

</script>

<p>UserName</p>
<input type="text" style="margin-left:30px;width:150px;margin-top:10px;margin-bottom:10px;" id="UserId" onblur="Username()" />
<p>Password1</p>
<input type="password" id="Password1" style="margin-left:30px;width:150px;margin-top:5px;margin-bottom:10px;" onblur="pwdCheck1()" />
<p>Password2</p>
<input type="password" id="Password2" style="margin-left:30px;width:150px;margin-top:5px;margin-bottom:10px;" onblur="pwdCheck2()" />
<input type="button" onclick="alert('Login Successful')" value="Log In" style="margin:10px 10px 5px 5px" />

You can modify this code I provided so you get a picture how it works because the code you provided I can't picture in my mind how it works.

Edited by LastMitch: grammer

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.