PDA

View Full Version : using a specified value by the user in HTML


Ricky158
09-09-2002, 11:21 PM
i am not sure if this has already been asked and answered, because i cant do a search containing var (under the minimum of 4 characters in a search). i dont know what i did wrong there, though. so i thought i should just make a new thread then.


here's what i want to do...

On the main page (index.html) i want to have a prompt pop up asking for the user's name. so far so good. but i want to create a new page, but still have that user's name appear on the page.

a specific description of why i would need this, is that i am making a site that first asks the person "What is your name?" I've got all the Java to work so far. but i want to (somehow) use that person's name throughout the site. because it is an RPG site, and the main character (the user) must have the user's name in it. so if i type in "Ricky" as my name, I want it to say "Commander Ricky" throughout the entire site. i am using the person's name in only a few different places in the entire site, but the places that i am using the name, is on different .html pages.


any help would be greatly appreciated

THANKS!!!

Cloudski
09-09-2002, 11:43 PM
I do not think Javascript can do this... Although I don't know what the situation fully is, but a server-side language may be needed... (PHP,ASI,CGI... etc...) But, I could be wrong...

Hope that at least helps a little :thumbsup:

whammy
09-10-2002, 02:03 AM
You could use a cookie. But a server-side language will be a better solution. Barring that, look up the cookie tutorials on http://www.javascriptkit.com. I'm sure they will hold many answers for you and point you in the right direction.

martin_narg
09-10-2002, 07:44 AM
The other option is to use frames and store the name in a variable in another frame. You could set up a frameset with a top frame having a height of 0 and another frame using the rest of the screen. Then you only need to change the large frame href/content.

Hope this helps.

m_n

Ricky158
09-11-2002, 02:50 AM
well, as a matter of fact, i already have frames set up on the page. would this eliminate the use of cookies?

i have one (smaller) frame being used for navigation, and the other for showing the web pages. the navigation frame is "nav.html" and the other frame is "main.html"

does this simplify things a bit?

glenngv
09-11-2002, 03:10 AM
in your nav.html

<script>
var myname=prompt("What is your name?","");
</script>


then in your pages in the 2nd frame.
assuming the navigation frame is the first frame
<script>
if (top.frames[0]) document.write(top.frames[0].myname)
</script>

Ricky158
09-11-2002, 04:09 AM
here is the script i have in the navigation frame. just so i dont get confused with file names and stuff...

<script language="JavaScript">
<!-- Cloaking device on!
var yourname = prompt("What is your name?", "Type your name here ...");
alert("Hello, "+yourname+" and welcome to... BLAH BLAH BLAH");
// Cloaking device off -->
</script>

so, after the user types in their name, a prompt comes up with a welcome to the site, and it uses their name in the prompt twice (and one later on in the context "Commander (their name)")


thanks