onChange Event not working

onClick event run ajax request to a php file whos output should start

Page 1 of 1

2 Replies - 3097 Views - Last Post: 27 February 2009 - 08:23 PM

#1 ARCSET  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 13-June 08

onChange Event not working

Posted 27 February 2009 - 04:29 PM

Here is the problem my onchange event is not working. here are the samples of the code.....

You start by clicking Submit after you enter username and password in textfields
Login HTML (just the submit part)
<a onclick="loginajax();" onmouseover="ChangeColor('loginsubmit', '000000');" onmouseout="ChangeColor('loginsubmit', 'ffffff');" style="cursor:default"><font color="#FFFFFF" id="loginsubmit"><b>Submit</b></font></a>


The submit button runs loginajax();
aj_makerequest(location of file, where to put the output via ID, javascript to run if ajax request goes through, Custom Error message if ajax doesnt go through, Is It a input tag);
loginajax();
function loginajax(){
	AjaxWait("loginfail");
	var passlogin=document.getElementById('passlogin').value;
	var userlogin=document.getElementById('userlogin').value;
	aj_makeRequest("includes/Login.php?userlogin="+userlogin+"&passlogin="+passlogin+"","hiddenlogin","","No SQL","YES");
}


The ajax runs a php code the checks a database and starts a session then brings back output ether "PASS" or "FAIL" and places it in a input tag that is in a display:hidden table that should onchange run logincheck();
<input type="text" id="hiddenlogin" onchange="logincheck();"/>


Logincheck();
function logincheck(){
	res = document.getElementById("hiddenlogin").value;
	if(res == "PASS"){
	document.getElementById("loginfail").value = "<font color=\"#1D700E\"><b>PASS</b></font>";
	location.reload(true);
	}else if (res =="FAIL"){
	document.getElementById("loginfail").value = "<font color=\"#C40000\"><b>FAIL</b></font>";
	}else if (res == "No SQL"){
	document.getElementById("loginfail").value = "<font color=\"#C40000\"><b>No SQL</b></font>";
	}
}


My problem is that it doesn't run Logincheck(); when the the value is changed in id="hiddenlogin" by the php "PASS" or "FAIL"

Anyone know whats wrong????? Thanks alot :)

This post has been edited by ARCSET: 27 February 2009 - 04:34 PM


Is This A Good Question/Topic? 0
  • +

Replies To: onChange Event not working

#2 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1199
  • View blog
  • Posts: 7,309
  • Joined: 07-September 06

Re: onChange Event not working

Posted 27 February 2009 - 05:40 PM

onchange events for text and password inputs (and probably others too) only fire on blur, so you have to type things in then click off of the inout, so it isn't selected for the onchange event to realize that something has happened.

What you need to do if you want to do things real time, use the onkeypress event to get whenever any character has been pressed on the keyboard.

HTH
Was This Post Helpful? 0
  • +
  • -

#3 ARCSET  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 13-June 08

Re: onChange Event not working

Posted 27 February 2009 - 08:23 PM

well its programically changed by the ajax to php to input field.

i could run the ajax function and then have it run the javascript function logincheck() with a extra else statment that will make a loop until one of the previous accept responses from the PHP is returned.

ajax_makeRequest(location of file, where to put the output via ID, javascript to run if ajax request goes through, Custom Error message if ajax doesnt go through, Is It a input tag);

aj_makeRequest("includes/Login.php?userlogin="+userlogin+"&passlogin="+passlogin+"","hiddenlogin","logincheck","No SQL","YES");


logincheck()
logincheck(){

  res = document.getElementById("hiddenlogin").value;
	if(res == "PASS"){
	document.getElementById("loginfail").value = "<font color=\"#1D700E\"><b>PASS</b></font>";
	location.reload(true);
	}else if (res =="FAIL"){
	document.getElementById("loginfail").value = "<font color=\"#C40000\"><b>FAIL</b></font>";
	}else if (res == "No SQL"){
	document.getElementById("loginfail").value = "<font color=\"#C40000\"><b>No SQL</b></font>";
	}else{
	setTimeout("logincheck()",1000);
	}
	
}

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1