Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-19-2011, 06:46 PM   PM User | #1
reader
New to the CF scene

 
Join Date: Mar 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
reader is an unknown quantity at this point
Ajax xml login help

I wrote the following code that is a login form for user accounts stored in xml files but when i try to login no popup box shows up could someone please tell me what I did wrong

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<style type=text/css>
</style>

<script type=text/javascript>
	function login(){
	var xmlhttp;
	var login=document.getElementById("login");
	var xmlDoc=xmlhttp.responseXML;
	if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
    else
	{
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
	xmlhttp.open("GET","/users/" + login.elements[0].value + ".xml", true);
	xml.send();
	if (xmlDoc.getElementByTagName("username")==login.elements[0].value)
	{
		if (xmlDoc.getElementByTagName("password")==login.elements[1].value)
		{
			alert ("You have entered the correct username and password");
		}
		else
		{
			alert ("Incorrect username or password");
		}
	}
	else
	{
		alert("Incorrect username or password");
	}
</script>



</head>
<body>
<div id=login>
    <form name=login id=login>
	    Username: <input type=text name=login_username id=username />
	    <br />
	    Password: <input type=password name=login_pass id=password />
	    <br />
	    <input type=submit class=button value=Submit onClick=javascript.login() />
	</form>
</div>

<style language=javascript>
</style>

</body>
</html>
reader is offline   Reply With Quote
Old 03-20-2011, 04:18 PM   PM User | #2
MarPlo
Regular Coder

 
Join Date: Mar 2011
Posts: 145
Thanks: 0
Thanked 20 Times in 20 Posts
MarPlo is an unknown quantity at this point
Hy,
getElementByTagName("password") contains an array of all tags "password"
Try getElementByTagName("password")[0]
Also, the values of attributes in the html form should be within quote id="password" and the others.
If still don't works, see the examples from Ajax and XML tutorial.
__________________
MarPlo is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:09 PM.


Advertisement
Log in to turn off these ads.