Page 1 of 3 123 LastLast
Results 1 to 10 of 24

Thread: Please Help With Window.location

  1. #1
    Join Date
    Mar 2008
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Please Help With Window.location

    Hi, guys i really need help with one thing
    i am trying on my index page to use a form with a cookie so that when they enter they username on the index page, it uses window.location to reload the index page with their name

    i know its simple but i cant figure it out
    please help

  2. #2
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    This link should keep you moving
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  3. #3
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Rangana, I think he wants an input type.
    Jeremy | jfein.net

  4. #4
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    Something like this
    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title></title>
    <script type="text/javascript">
    function myCookie(name,value,days) {
    	if (days) {
    		var date = new Date();
    		date.setTime(date.getTime()+(days*24*60*60*1000));
    		var expires = "; expires="+date.toGMTString();
    	}
    	else var expires = "";
    	document.cookie = name+"="+value+expires+"; path=/";
    }
    
    function readmyCookie(name) {
    	var nameEquiv = name + "=";
    	var ca = document.cookie.split(';');
    	for(var i=0;i < ca.length;i++) {
    		var c = ca[i];
    		while (c.charAt(0)==' ') c = c.substring(1,c.length);
    		if (c.indexOf(nameEquiv) == 0) return c.substring(nameEquiv.length,c.length);
    	}
    	return null;
    }
    window.onload = function()
    {
    	if(readmyCookie('username') != null)
    	{
    		document.getElementById('name').firstChild.nodeValue = readmyCookie('username');
    	}
    }
    </script>
    </head>
    
    <body>
    <span id="name">&nbsp;</span>
    <form action="" method="post">
    <input type="text" name="myusername">
    <input type="submit" value="Submit" onclick="myCookie('username',this.form.myusername.value,800);">
    </form>
    </body>
    </html>
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  5. #5
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    A little edit to your code Ragana, but if mine suits best for you, thanks Ragana:
    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title></title>
    <script type="text/javascript">
    function myCookie(name,value,days) {
    	if (days) {
    		var date = new Date();
    		date.setTime(date.getTime()+(days*24*60*60*1000));
    		var expires = "; expires="+date.toGMTString();
    	}
    	else var expires = "";
    	document.cookie = name+"="+value+expires+"; path=/";
    }
    
    function readmyCookie(name) {
    	var nameEquiv = name + "=";
    	var ca = document.cookie.split(';');
    	for(var i=0;i < ca.length;i++) {
    		var c = ca[i];
    		while (c.charAt(0)==' ') c = c.substring(1,c.length);
    		if (c.indexOf(nameEquiv) == 0) return c.substring(nameEquiv.length,c.length);
    	}
    	return null;
    }
    window.onload = function()
    {
    	if(readmyCookie('username') != null)
    	{
    		document.getElementById('name').firstChild.nodeValue = readmyCookie('username');
    		document.getElementById('n').innerHTML="";
    	} 
    }
    </script>
    </head>
    
    <body>
    <span id="name">&nbsp;</span>
    <form action="" method="post"><span id="n">
    <input type="text" name="myusername" onChange="myCookie('username',this.form.myusername.value,800);"></span>
    </form>
    </body>
    </html>
    Jeremy | jfein.net

  6. #6
    Join Date
    Mar 2008
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi thanks for your help
    every time i open this on internet explorer. it says "to help protect your security, internet explorer has restricted this webpage from running scripts or activex that could access your computer." is there anyway i can do this without that message coming up
    and also how do i set a greeting saying welcome "username"
    and is there anyway i can use window.location to reload the page
    thanks

  7. #7
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    That warning does'nt happen when the page is in the server..only on local machine

    Add this code in the onload event?
    Code:
    document.getElementById("myusername").style.display="none";
    window.location is the same as document.location (maybe) which automaticallyt reloads the page

    Make sure you had cleared your cache already
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  8. #8
    Join Date
    Mar 2008
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks for your help
    but the submit still stays after i added the new code
    any reason why this is so?
    also how do i add a greeting that says welcome "user"
    thanks

  9. #9
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    Maybe this will aide
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Untitled Document</title>
    <style type="text/css">
    #name
    {
    border:3px double #222;
    width:760px;
    }
    </style>
    <script type="text/javascript">
    function createCookie(name,value,days)
    {
    	if(days)
    	{
    		var date = new Date();
    		date.setTime(date.getTime()+(days*24*60*60*1000));
    		var expires = "; expires="+date.toGMTString();
    	}
    	else var expires = "";
    	document.cookie = name+"="+value+expires+"; path=/";
    }
    
    function readCookie(name)
    {
    	var nameEQ = name + "=";
    	var ca = document.cookie.split(';');
    	for(var i = 0;i < ca.length;i++)
    	{
    		var c = ca[i];
    		while (c.charAt(0) == ' ') c = c.substring(1,c.length);
    		if(c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    	}
    	return null;
    }
    window.onload = function()
    {
    	if(readCookie('username') != null)
    	{
    		document.getElementById('name').firstChild.nodeValue = "Welcome back, " + readCookie('username');
    		document.getElementById("nameinputform").style.display="none";	
    	}
    	else
    	{
    		document.getElementById('name').firstChild.nodeValue = "Welcome, Guest!";
    	}
    }
    </script>
    </head>
    <body>
    <span id="name">&nbsp;</span>
    <form action="" method="post" id="nameinputform" onsubmit="createCookie('username',this.uname.value,888);">
    	<label for="uname">Please Enter Your Name:
    	<input type="text" name="uname" id="uname">
    	</label>
    	<input type="submit" value="Send">
    </form>
    </body>
    </html>
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  10. #10
    Join Date
    Mar 2008
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    hey guys thanks for all your help
    I was also wondering how can i make the cookie expire after the browser closes
    here it doesnt seem to expire

Bookmarks

Posting Permissions

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