View Full Version : Ajax xml login help

03-19-2011, 07:46 PM
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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<style type=text/css>

<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();
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET","/users/" + login.elements[0].value + ".xml", true);
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");
alert ("Incorrect username or password");
alert("Incorrect username or password");

<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() />

<style language=javascript>


03-20-2011, 05:18 PM
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 (http://www.coursesweb.net/ajax/ajax-xml) tutorial.