Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Message Alert Help 1

Status
Not open for further replies.

26022602

Technical User
Nov 23, 2010
11
US
Hello, I am a newbie to javascript and I would like to make the code below stay on the website's homepage for as long as a viewer is on the site. I am trying to make the website as personalized as possible but I don't want the same viewer typing h/her name every time h/she goes back to the homepage. Thanks and any help is highly appreciated.


<!-- Start of Hello Visitor JavaScript-->
<!-- DESCRIPTION: This will ask the user for his/her name, then tell them WELCOME.

<!-- INSTRUCTIONS: Place this script below the BODY tag, before you start the content of your page.

<!-- FUNCTIONALITY: Works in both Netscape and IE.
-->
{
var name = prompt ('Please type in your name for personalized greeting','');
var color = prompt ('Please choose your color','');
document.write("<CENTER><FONT FACE=ARIAdL,VERDANA COLOR="+color+" >Hello "+name+", Welcome to Willamette Family</FONT></CENTER><P>")
}
//-->
 
It should be fine. The cookie won't be modified any more.
 
@op
Why the red colored lines for the name testing part? Never seen anything like that in any language.

Change d_default to 0 is not an option for the implementation of setCookie. Besides it means delete the cookie whereas you want to set the cookie in case nothing pass to the function as the 3rd arguments! You can change it to 0.25 or whatever, not zero or negative number.

At the time of my posting my last amendment, I had already spared some time to test the final result. It is working as expected and the cookie is set just fine.
 
Hi

tsuji, I am not talking about the cookie now. Its about the flow : the [tt]document[/tt] is already closed when [tt]onload[/tt] happens, so [tt]document.write()[/tt] will perform an implicit [tt]document.open()[/tt] discarding the current content.


Feherke.
 
That's what I meant too as the cookie's function is no longer needed.
 
@Feherke, you know as well as I that document.write is mostly for novice in that kind of position and use. In case there are things outside script tag and in the body, it should always be replaced with the approach of getting those references of div or p or whatever and sent the innerHTML to those element. That part is hopelessly primitive just yet as you see the use of center and font...
 
[2.2] Upon reading what I posted, I seem to have missed out a closing curly brace!
[tt]
window.onload=function() {
var name=getCookie('name')
if (!name) {
name = prompt ('Please type in your name for personalized greeting','');
if (name) setCookie('name',name)
}
var color=getCookie('color')
if (!color) {
color = prompt ('Please choose your color','');
if (color) setCookie('color',color)
}
document.write("<CENTER><FONT FACE='ARIAL,VERDANA' COLOR='"+color+"'>Hello "+name+", Welcome to Willamette Family</FONT></CENTER><P />")
[red]}[/red]
</script>
[/tt]
[2.3] But op likes their own script style and own language. In that sense, I pass. I have zero thing more to add.
 
@tsuji

The red colored line on the script was meant to show the lines I was asking some help with (sorry, it wasn't clear)

I really, really appreciate all the time that you spared in trying to help me out and don't how to thank you enough. I don't have any preference over one language type or style over another, I was just mostly interested in trying to make this one work for me. I don't have any doubt that that script was working perfectly fine when you tested it, but it wasn't not for me and I had to try to find ways to make it work from the very limited knowledge I've acquired (about 2 weeks ago) from the internet. It was not my intention to discard parts of what you wrote, it was just for the simple reason that I desperately want to make this happen.

As you pointed out with your conversation with feherke, I am very much a novice and still don't know what I was doing.

I thank you sincerely for all your help and assistance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top