IntelliJ Java IDE
The moose likes HTML, CSS and JavaScript and the fly likes Passing Variables Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "Passing Variables" Watch "Passing Variables" New topic
Author

Passing Variables

Roisin Dunne
Greenhorn

Joined: Feb 19, 2004
Posts: 12
i am building a logon page using javascript and the database is in XML
once the user logs on they are directed to a new page depending on what type of user they are!
is there anyway i can use the username which has been entered in the logon and pass the details to the page they are directed to???/
tahnks
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15003
It is alot easier when you are using a serverside language with posting a form and it is more secure to do it.
Can you do it with JavaScript, in some ways yes...
Method 1: Query String
Method 2: Cookies
The forum here uses both methods...The query String is used to determine what the page does and the cookies store your username...
If you want more informtion, just ask...
Eric
Roisin Dunne
Greenhorn

Joined: Feb 19, 2004
Posts: 12
so how do i use the query string method?
im not sure about the cookies as most browsers dont support them anymore do they?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15003
All browsers support cookies unless a person turns them off, this site uses them as I said before.

Query String...easy....
on the page you want to get the value
say the URL was:
http://thepage.com?forum=20
all you would need to do is the following

You can use the "get" method with a form for the query string. The method above only assumes that there is going to be one value in your QS.
Eric
Roisin Dunne
Greenhorn

Joined: Feb 19, 2004
Posts: 12
sorry
rite but my page doesnt have a ? after it!the varable is simply in a textbox on that page!how can i refernce it on next page?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15003
you have to make it have a query string with either a form or adding to the url and sending it to the next page...
1)Form using Get
2)document.loaction.href= "http://url" + "?theVar=" + yourVar;
3)Cookies...
4)Use a server side language
 
 
subject: Passing Variables
 
Threads others viewed
How to link out on jsp
NT Domain authentication via JAAS & Tomcat
problem without logout, how to solve it
What Is The Proper Design - Security
JSP redirection after session timeout
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com