Running Login Validation that is causing problems. Client side 'onchange' of input id=customer email is not writting to <p> for each 'if' statement. Any help greatly appreciated.

var dbemailstr = ['heinzstapff@hotmail.com']; // emulate database email search
var newemailstr = ['gloriamarks@prodigy.net']; // emulate add to databas email addresses
var email = customeremail.value; // accessed with getElementById
var loginrequest = document.getElementById('loginrequest'); // <p> in login container
var matchemailstr = function() {
var atpos = email.indexOf("@");// test email input 
var stoppos = email.lastIndexOf(".");// test email input 
if (atpos == -1 || stoppos == -1) { // test email input || or symbol forces return of 'true' ?
loginrequest.innerHTML = 'Not a valid email address!';
 // loginrequest.innerHTML change not made?
}
if (stoppos < atpos) { // test email input
loginrequest.innerHTML = 'Not a valid email address!';
 // loginrequest.innerHTML change not made?
}
if (stoppos - atpos == 1) { // test email input
loginrequest.innerHTML = 'Not a valid email address!';
 // loginrequest.innerHTML change not made?
} 
if(customeremail.value == dbemailstr) { // emulate database email search
customerpasswordlist.className = 'loginlist'; // list and input appear?
customernewpasswordlist.className = 'loginlist'; // list and input appear?
loginrequest.innerHTML = 'Welcome back, please enter your password or make relevant changes!';
 // loginrequest.innerHTML change not made?
}
if(customeremail.value == newemailstr) { // emulate add to databas email addresses
loginrequest.innerHTML='Welcome,You should create a password to login and register.';
 // loginrequest.innerHTML change not made?
}
else{
loginrequest.innerHTML = 'Sorry, No Match Found, Press Continue to register!'; // only loginrequest.innerHTML change made?
}}

addEvent(customeremail,'change',function(){ matchemailstr(); }, true); // || or symbol return true
// uses addEvent from Chapman@about.com

Ok. I changed the script statements to "else if" as sugested on MSDN forums but I can't get It to work Maybe I'll search for "else if". The <p> element id 'loginrequest' that Im trying to affect with innerHTML only gets affected by the first "if" statement even if the email address is real 'loginrequest' outputs "Not a valid email address".

var customeremail = document.getElementById('customeremail');
var email = customeremail.value;
var loginrequest = document.getElementById('loginrequest');
var dbemailstr = ['heinzstapff@hotmail.com']; 
var newemailstr = ['gloriamarks@prodigy.net'];  
var atpos = email.indexOf("@");
var stoppos = email.lastIndexOf(".");

var checklogin = function(){  
if (atpos == -1 || stoppos == -1) { 
loginrequest.innerHTML = 'Not a valid email address!';
customeremail.focus();
return false;
}
else if(stoppos < atpos) { 
loginrequest.innerHTML = 'Not a valid email address!';
customeremail.focus();
return false;
}
else if(stoppos - atpos == 1) { 
loginrequest.innerHTML = 'Not a valid email address!';
customeremail.focus();
return false;
} 
else if(email == dbemailstr) {
loginrequest.innerHTML = 'Welcome back, please enter your password or make relevant changes!';
document.getElementById('customerpasswordlist').className = 'loginlist'; 
document.getElementById('customernewpasswordlist').className = 'loginlist'; 
return false;
}
else if(email !== dbemailstr) { 
loginrequest.innerHTML='Welcome,You should create a password to login and register.';
return false; 
}
else{                 
return true;   
}   
} 

addEvent(customeremail,'change',function(){ checklogin();},false);

It's probably the "return false;" or "return true;" statements?

AutisticCuckoo
Member of Site Point Forum
Thanks for reminding me about overwriting the first "if" with every if after. This is what happens when your deslexic.:-/
Correct me if I am wrong but the last "else" Statement should produce the "result" you want?
A "else if" might be better for this situation? It should produce a response for each "else if". Planning is everything? Something like this:

var checklogin=function(){ //refrence login input onchange
[B]if[/B](login.value!==email address correct syntax){
1.'Loginrequest' <p> .innerHTML='Please enter a Valid E-mail Address';
}
[B]else if[/B](login.value == email address correct syntax){
2.'Loginrequest' <p> .innerHTML='Welcome,Create a Password to Login';
   produce password input;
   produce password confirm input;
}
[B]else if[/B](login.value == database email address){
3.'Loginrequest' <p> .innerHTML='Welcome Back Joe, Login or make changes';
   produce password input;
   produce mail me my password link;
   produce change my password link;
}
[B]else[/B]{
3.'Loginrequest' <p> .innerHTML='Please Enter Your E-mail Address';
}}
addEvent(//call login onchange);

Funny thing is that the added inputs still have to be scripted:S

'AutisticCuckoo' Member of Site Point Forum
Sorry Guy I haven't had the chance to re-write the "else if". The first time I tried it failed but I might have written "if else". Thanks to your comments about over-writting the first "if" I can now approach it with a little more "Clarity". :)
Suprisinglly very little response from these forums. It must be a trade secret or "Mundane" javascript exersize. It could be the key to "Javascript" success. Client-Side Form Validation? :-O
Hopefully I wil get back to resolve this post in the next couple of days. :zzz:

AutisticCuckoo Member Site Point Forum
Thanks for the Edicate reminder. It never pays to be less than "Clear" or "Disrespectfull" to the script "Gods".;)
Still haven't re-written the "else if" so when I do I might need to post it under a different Title as well as posting 'Resolved' on the ones I have.
Mardi-Gras or Carnival?
Dose touch on another issue of viewing the number of people who have viewed a post. I KNOW I am self involved/selfish but I'd like to see the number of people who viewed the post on the post itself. I don't always have time to review the actual Forum posts which at present is the only means of seeing how many people viewed the specific post. Possabley in the head of each post if not the head of each thread? :confused:
Best regards to all concerned.

AutisticCuckoo Member Site Point Forum
Got this working fine. Sorry it took so long.

var login = document.getElementById('login');
var emailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/;   
var loginrequest = document.getElementById('loginrequest');
var dbemailstr = 'heinzstapff@hotmail.com'; 
function checklogin(){ 
if(login.value.match(dbemailstr)) {
loginrequest.innerHTML = 'Welcome back Heinz, please enter your password or make relevant changes!';
document.getElementById('passwordlist').className = 'loginlist'; 
document.getElementById('emailpasslist').className = 'loginlist'; 
document.getElementById('changepasslist').className = 'loginlist'; 
document.getElementById('pass2list').className = 'hide'; 
return false;
}
if(emailformat.test(login.value)){ 
loginrequest.innerHTML='Welcome,You should create a password to login and register.';
document.getElementById('passwordlist').className = 'loginlist'; 
document.getElementById('pass2list').className = 'loginlist'; 
document.getElementById('emailpasslist').className = 'hide'; 
document.getElementById('changepasslist').className = 'hide'; 
return false;
}
else { 
loginrequest.innerHTML='Please Enter a Valid E-mail Address to login and register!';
document.getElementById('passwordlist').className = 'hide'; 
document.getElementById('emailpasslist').className = 'hide'; 
document.getElementById('changepasslist').className = 'hide'; 
document.getElementById('pass2list').className = 'hide';
return true;
}
}   
 
addEvent(login,'change',function(){ checklogin();},false);
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.