Jump to content

Java Cookie = Show Name in a list


morrisjohnny

Recommended Posts

Okay this code has been taken fomr the w3Schools site so it asks the user for their username, I was wondering is it possible to display their name somewhere eles on the page and not in a message box that appears.I would like it to appear in two places could someone explain how this can be done?( Why two places?First place, I would like near their top so it says "Welcome (Username)"Second Place, I would like in the side of the page ( not sure which side ) so it says "Users Online: (Username1) (Username2)" Ect, i can use php any mysql, but i can't find a host that will do free hosting :)Thanks in Advance-JnyI know i still need to remove the section to stop the button coming up that says welcome

<html><head><script type="text/javascript">function getCookie(c_name){if (document.cookie.length>0){ c_start=document.cookie.indexOf(c_name + "=")if (c_start!=-1){ c_start=c_start + c_name.length+1 c_end=document.cookie.indexOf(";",c_start)if (c_end==-1) c_end=document.cookie.lengthreturn unescape(document.cookie.substring(c_start,c_end))} }return null}function setCookie(c_name,value,expiredays){var exdate=new Date()exdate.setDate(exdate.getDate()+expiredays)document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : "; expires="+exdate)}function checkCookie(){username=getCookie('username')if (username!=null)  {alert('Welcome again '+username+'!')}else   {  username=prompt('Please enter your name:',"")  if (username!=null && username!="")	{	setCookie('username',username,365)	}  }}</script></head><body onLoad="checkCookie()"></body></body></html>

Link to comment
Share on other sites

To get the welcome message in desired place, one thing you can do is to create a lable and have that in any desired location and onpage load set the value of the lable with the welcome msg using javascript...In the function "checkCookie()" instead of "alert" use "document.getElementById("labelname").value=welcome message"and in <body><label id="labelname"></label></body>

Link to comment
Share on other sites

It Doesn't Show If I Remove Alert it doesn't ask for my nameIf you could get it working Great :) I think Its obiouse that i have missed something out, Do u Merge the cookie Script and teh Web page together? cause thts what i have done, Please Help If possible

<html><head><title>Johnnys Junk F1</title><link href="CSS/sheet.css" rel="stylesheet" type="text/css"/><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"><!-- Start of Cookie Script --><script type="text/javascript">function getCookie(c_name){if (document.cookie.length>0){ c_start=document.cookie.indexOf(c_name + "=")if (c_start!=-1){ c_start=c_start + c_name.length+1 c_end=document.cookie.indexOf(";",c_start)if (c_end==-1) c_end=document.cookie.lengthreturn unescape(document.cookie.substring(c_start,c_end))} }return null}function setCookie(c_name,value,expiredays){var exdate=new Date()exdate.setDate(exdate.getDate()+expiredays)document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : "; expires="+exdate)}function checkCookie(){username=getCookie('username')if (username!=null)  document.getElementById("Test").value=welcome messageelse   {  username=prompt('Please enter your name:',"")  if (username!=null && username!="")	{	setCookie('username',username,365)	}  }}</script></head><!-- End Cookie in Head --><body onLoad="checkCookie()"><!-- Open a main table that is 75% the width of the screen --><table border="1" cellspacing="1" width="75%" align="center">  <tr>	<td colspan="3" align="center"><p><marquee direction="up" height="50" scrollamount="3" onMouseover=this.scrollAmount="0" onMouseout=this.scrollAmount="3">Welcome To <br /><br /> . : : Johnnys Junk : : . <br /><br /> I Hope Enjoy Your Stay.<br /><br />Please feel Free to browse the site use facilities</marquee></p></td>  </tr>  <tr>	<th bgcolor='#181818' colspan="3" ><br /><center>Welcome <label id="Test"></label> To Johnnys Junk On <script type="text/javascript">var d=new Date()var weekday=new Array(7)weekday[0]="Sunday"weekday[1]="Monday"weekday[2]="Tuesday"weekday[3]="Wednesday"weekday[4]="Thursday"weekday[5]="Friday"weekday[6]="Saturday"document.write(weekday[d.getDay()] + " " + d.getDate());</script><script type="text/javascript">var d=new Date()var Month=new Array(12)Month[0]="January"Month[1]="Febuary"Month[2]="March"Month[3]="April"Month[4]="May"Month[5]="June"Month[6]="July"Month[7]="August"Month[8]="September"Month[9]="October"Month[10]="November"Month[11]="December"document.write(Month[d.getMonth()])</script> at<script type='text/javascript'>function startTime(){var today=new Date()var h=today.getHours()var m=today.getMinutes()var s=today.getSeconds()// add a zero in front of numbers<10m=checkTime(m)s=checkTime(s)document.getElementById('txt').innerHTML=h+':'+m+':'+st=setTimeout('startTime()',500)}function checkTime(i){if (i<10){i='0' + i}return i}</script><body onload="startTime()"><div id="txt"></div></center><br /></th>  </tr>  <tr>	<td colspan="3" align="center"><img src="Images/banner.jpg"><br/><br/><br/></td>  </tr>  <tr align="center">	<th width="15%" bgcolor='#181818' align='center'> - Navigation - </th><th width="70%" bgcolor='#181818' align='center'> - News - </th><th width="15%" bgcolor='#181818' align='center'> - ShoutBox - </th>  </tr>  <tr>				<td valign="Top"><script type="text/javascript" src="JS/Menu.js"></script></td>				<td valign="Top"><table width=100% border="1"><tr><th width="50%" align="center"><a href='http://www.f1.com'>Formula 1</a> News</th><th width="50%" align="center"><a href='http://81.179.53.97/?section=1'>F1-Tm</a> News</th>				 </tr><tr><td width="50%" align="center"><script type="text/javascript" language="JavaScript" src="http://www.totalf1.com/news/TotalF1News5.txt"></script></td><td width="50%" align="center"><script type="text/javascript" src="JS/F1.js"></script></td>				 </tr></table><center><colour="red">Note While this hopefully what the new Website will look like I am still trying to get it done While i Have decided To Upload what i can when i can, I Hope Everything Turns to normal Soon</colour></center></td>		   <td><!-- BEGIN MYSHOUTBOX.COM CODE --><iframe src="http://454520.myshoutbox.com/" width="152" height="300" frameborder="0" allowTransparency="true"></iframe><!-- END MYSHOUTBOX.COM CODE--></td>  </tr><tfoot> <tr><td colspan="3" align="center">© 2006 Johnny Morris.<td></tr></tfoot></table></body></body></html>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...