Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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>

  • #2
    Regular Coder
    Join Date
    Mar 2011
    Posts
    148
    Thanks
    0
    Thanked 20 Times in 20 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •