Jump to content

Pls help on xml/webserver.... It urgent. Plsss


Tonaldex
 Share

Recommended Posts

Am currently working on a website using xml as my database. Despite running the code from a webserver(IIS) when i click on my eventhandler (a button) hoping to validate a form cosisting of username and password, still nothing happen i have edited d javascript code time without no i even use d firefox error console to avoid error in my script despate all dis, i haven't been able to achieve my aim.. I.e to compare the username and paswoqd field to the username and password from the xml. Pls i need everybody's help. And special thanks to Dehire's dad 4 d last time.

Link to comment
Share on other sites

You should post your javascript. Learning how to extract values from an XML document is not easy. Even before that, you should make sure you have created an XML DOM. Several things can go wrong, especially with IE. Your XML may be correct, but JavaScript may only see it as a string, not as a document.

Link to comment
Share on other sites

Dis is my code.....

function validate(form,field1,field2,id1,id2){	with(form)	{		with(field1 && field2)				{			if(value==null || value=="")			{				alert("ALL FIELDS ARE REQUIRE, PLEASE SUPPLY YOUR USERNAME AND PASSWORD");				}						else if(value!=null && value!="")			{if(window.XMLHttpRequest)					{						xmlhttp=new XMLHttpRequest();						}						else if(window.ActiveXObject)						{							xmlhttp=new ActiveXObject("Microsoft.XMlHTTP");							}															xmlhttp.onreadystatechange=state_change(id1,id2);								xmlhttp.open("GET",details.xml,true);								xmlhttp.send();							xmlDoc=xmlhttp.responseXML;				}		}	}}	 

Edited by Tadecode
Link to comment
Share on other sites

Dis is my state_change function.....

	function state_change(a,	{		if(xmlhttp.readyState==4)		if(xmlhttp.status==200)		{		var w=	document.getElementByid("a").value;		var u=	document.getElementByid("b").value;		document.getElementById("talk").innerHTML=xmlhttp.responseText;		  var x= xmlDoc.getElementByTagName("user_deatails");			for(var loop=0; loop=x-1; loop++)			{				var y=x.firstChild.nodeValue;				var z=x.nextSibling;				if(w==y && u==z) 				{					document.location.href="register.html";				}					else					{						alert("USERNAME OR PASSWORD NOT VALID");						}					}				}		

Link to comment
Share on other sites

1. This syntax will never work:

with(form){with(field1 && field2){

I don't even want it to work. The with structure is annoying, and the tutorial you borrowed it from may not be suited to your situation, anyway. Just passing a reference to each field, and test the value of each field separately. Or don't pass any references at all. Instead, create the references inside your function by executing document.getElementById(id_of_element) . 2. This won't work either:

xmlhttp.onreadystatechange=state_change(id1,id2);

What you are trying to do is assign the state_change function to xmlhttp.onreadystatechange . Instead, by adding (id1,id2) to your assignment, you are executing state_change immediately, and assigning the return value of that function to xmlhttp.onreadystatechange . That is NOT what you want. The function executes too soon, and the return value is false. So when your AJAX object receives its response, nothing will happen.When you assign a function and it does not need variables passed to it, it looks like this:

xmlhttp.onreadystatechange=state_change;

See? No parentheses. What this does is assign a reference to the function. That is the only way the function will execute when the AJAX object gets its response.But it looks like you DO need to pass the function some data. (Make sure you really, really need to do that, by the way.) One way of doing it is this:

xmlhttp.onreadystatechange = function () {   state_change (id1, id2);}

If you don't understand anonymous functions yet, you should google the subject and read several articles to get a full understanding.I don't know if there are other problems, but these jump out at me.FWIW, it's a lot easier to debug code if you write a little bit at a time. If this were me, I would have worked on validating the form data before I added the AJAX part. Make sure one thing works perfectly. Then add the next big thing.

Edited by Deirdre's Dad
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...