January 9, 201115 yr Okay, I'm making an email client for a Uni assessment. Basically I need the input of the username to be stored globally so it can be accessed on different pages. This is my javascript. function logIn() { var userID = document.getElementById("username").value; var passWD = document.getElementById("password").value; var urllogin = url1 + "checkuser.php?" + "userID=" + userID + "&passWD=" + passWD ; if (window.XMLHttpRequest) { request=new XMLHttpRequest(); } else if (window.ActiveXObject) { request= new ActiveXObject("Microsoft.XMLHTTP"); } else alert("your browser does not support Ajax"); if(request!=null) { request.onreadystatechange = Resplogin; request.open("GET",urllogin,true); request.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); request.send(null); } } function Resplogin() { if (request.readyState==4) { if(request.status==200) { var response=request.responseText; alert(response); if (response == "registered") { window.location ="http://itsuite.it.brighton.ac.uk/ac315/finalmail/compose.html"; } } } } So basically I want to be able to store the username Globallyto be used on other pages. Any ideas?
January 10, 201115 yr In JavaScript, a global variable is one which may be accessed by any function. In your case, they are "logIn" and "Resplogin" as well as the standard "window" and "document". They aren't consistent across pages since JavaScript is predominantly a client-side script. To get a variable from one page to another, you need to store it server-side. This is best done with a server-size lanauge such as PHP, JSP or ASP but there is a purely JavaScript solution: cookies. More information about them and a couple of helpful functions may be found on quirksmode
January 14, 201115 yr Author Cheers man. Found this out when I went in to ask my lecturer. Ended up doing it all on one page and showing/hiding DIVs. http://itsuite.it.brighton.ac.uk/ac315/mail/index.html
Create an account or sign in to comment