473,545 Members | 2,001 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help displaying things

Okay, I'm still really new to javascript, so I'm looking for a little help. I
want to grab a name with I'm trying to display a hyperlink in my body, but one of
my functions overwrites it. The code is below. What am I doing wrong?

Thanks!
David

<html>
<head>
<title>
</title>
<script language="javas cript" type="text/javascript">
var userName = "";
var randomMessage = "";
function loadPage()
{
userName = prompt("What is your name?", "Please enter your name");
if ((userName == "Please enter your name") || (userName == null))
{
userName = "Anonymous User";
}
document.writel n('Welcome to my web page, ' + userName);
}

function mouseIsOver(sit e)
{
mouseIsOverMess age = "This link will take you to www." + site;
window.status = mouseIsOverMess age;
}

function mouseIsOut(site )
{
mouseIsOutMessa ge = "Are you sure you don't want to give www." +
site + " a shot?";
window.status = mouseIsOutMessa ge;
}

function mouseHasClicked (site)
{
randomNumber = Math.floor(Math .random()*5);
switch (randomNumber)
{
case "0":
randomMessage = "Hang onto your butt, we're heading
to www." + site + "!";
break;
case "1":
randomMessage = "Destinatio n: www." + site;
break;
case "2":
randomMessage = "www." + site + "? Energize!";
break;
case "3":
randomMessage = "Are you ready to visit www." + site
+ "? Here we go!";
break;
case "4":
randomMessage = "So, you think www." + site + " is
better?! Take a look";
break;
}
alert(randomMes sage);
}
</script>
</title>
</head>
<body onLoad="loadPag e();">
<h1 align="center">
Here are a few of my favorite links
</h1>
<hr />
<a href="http://www.slashdot.or g" onMouseOver="mo useIsOver
('slashdot.org' );" onMouseOut="mou seIsOut('slashd ot.org');"
onClick="mouseH asClicked('slas hdot.org');">
Slashdot
</a>
</body>
</html>
--
--------------------------------- --- -- -
Posted with NewsLeecher v3.9 Beta 1
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -

May 24 '07 #1
4 1371
Lee
merlin_at@merli nsrealm_dot_net said:
>
Okay, I'm still really new to javascript, so I'm looking for a little help. I
want to grab a name with I'm trying to display a hyperlink in my body, but one
of
my functions overwrites it. The code is below. What am I doing wrong?

Thanks!
David

<html>
<head>
<title>
</title>
<script language="javas cript" type="text/javascript">
var userName = "";
var randomMessage = "";
function loadPage()
{
userName = prompt("What is your name?", "Please enter your name");
if ((userName == "Please enter your name") || (userName == null))
{
userName = "Anonymous User";
}
document.writel n('Welcome to my web page, ' + userName);
}
1. You didn't explain clearly what it is that you're trying to do.
2. You included far too much whitespace in the code you posted.
As you can see, this makes it wrap and become difficult to read.
3. You used document.writel n() in a page that has already been
rendered. This clears the page and writes new content.
--

May 24 '07 #2
On May 24, 5:24 pm, Lee <REM0VElbspamt. ..@cox.netwrote :
merlin_at@merli nsrealm_dot_net said:


Okay, I'm still really new to javascript, so I'm looking for a little help. I
want to grab a name with I'm trying to display a hyperlink in my body, but one
of
my functions overwrites it. The code is below. What am I doing wrong?
Thanks!
David
<html>
<head>
<title>
</title>
<script language="javas cript" type="text/javascript">
var userName = "";
var randomMessage = "";
function loadPage()
{
userName = prompt("What is your name?", "Please enter your name");
if ((userName == "Please enter your name") || (userName == null))
{
userName = "Anonymous User";
}
document.writel n('Welcome to my web page, ' + userName);
}

1. You didn't explain clearly what it is that you're trying to do.
2. You included far too much whitespace in the code you posted.
As you can see, this makes it wrap and become difficult to read.
3. You used document.writel n() in a page that has already been
rendered. This clears the page and writes new content.

--
As Lee explained it in his 3. sentence, you rewrite your document so
none of the previous contents is left. Here's the thing - you can use
document.write( ln) in two situations:
1. <script>
function loading()
{
document.write( "bla" );
}
</script>
<body onload="loading ()">
.....
</body>
In this situation, after the whole document is loaded, it executes the
given function. BUT, between these two steps the document does an
implicit .close() method of itself, so you can't write on it anymore.
If you still try, however, like we did in the loading() function, then
the document is reopened by an implicit .open() method, which rewrites
all of its contents.
2. <body>
..........
<script>
document.write( "bla" );
</script>
..........
</body>
In this situation, however, the document is parsed line-by-line, as
usual, and when it comes upon the <scriptblock, the document hasn't
yet finished with loading, thus it hasn't yet called the
implicit .close() method, and document.write( "bla" ) acts as we
wanted - it just inserts the "bla" string in the place where the
<scriptblock is. After that the rest of the document is loaded, and
we can see all the contents as we wanted it.

What you're trying to do shouldn't use document.write at all. You
should make a <div id="bla_place"> </divelement in the document,
which is (as you can see) empty of contents but has an identifier
"bla_place" . The loading (<body onload="loading ()">) function should
look something like this:
function loading()
{
// ... you get the name by either prompt() or whatever
var bla_place = document.getEle mentById( "bla_place" );
bla_place.inner HTML = "Hello, " + name + "!";
}

You could of course use the DOM, instead of innerHTML, but for trivial
tasks such as this, it's really not necessary.

May 24 '07 #3
Sorry about the whitespace, I copied & pasted from my editor. What I'm trying to
do is simply display 2 things. The first is just a basic "Welcome to my web
site, " with the name the user enters onload. Then I just want to display a
hyperlink that includes onMouseOver(), onMouseOut(), and onClick(). I found out
that write() and writeln() clear the page, so what other options are there?

Thanks again!
~ David
--
--------------------------------- --- -- -
Posted with NewsLeecher v3.9 Beta 1
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -

May 24 '07 #4
On May 25, 12:24 am, merlin (merlin_at@merl insrealm_dot_ne t) wrote:
Sorry about the whitespace, I copied & pasted from my editor. What I'm trying to
do is simply display 2 things. The first is just a basic "Welcome to my web
site, " with the name the user enters onload. Then I just want to display a
hyperlink that includes onMouseOver(), onMouseOut(), and onClick(). I found out
that write() and writeln() clear the page, so what other options are there?
Maybe better if you quote previous messages.
<html>
<html>
<head>
<title>
</title>
<script language="javas cript" type="text/javascript">
var userName = "";
var randomMessage = "";
function loadPage()
{
userName = prompt("What is your name?", "Please enter your name");
if ((userName == "Please enter your name") || (userName == null))
{
userName = "Anonymous User";
}
document.writel n('Welcome to my web page, ' + userName);
// As Darko suggested, use div element to display the message.
document.getEle mentById('msgAr ea').innerHTML = 'Welcome to my web
page, ' + userName;
}

function mouseIsOver(sit e)
{
mouseIsOverMess age = "This link will take you to www." + site;
// Use div to display messages too..
document.getEle mentById('msgAr ea').innerHTML = mouseIsOverMess age;
}

function mouseIsOut(site )
{
mouseIsOutMessa ge = "Are you sure you don't want to give www." +
site + " a shot?";
window.status = mouseIsOutMessa ge;
// this one too..
document.getEle mentById('msgAr ea').innerHTML = mouseIsOutMessa ge;
}

function mouseHasClicked (site)
{
randomNumber = Math.floor(Math .random()*5);
switch (randomNumber)
{
case "0":
// type of randomNumber is number, try test it with alert(typeof
randomNumber);
// so remove double quotes surrounding the number
case 0:
randomMessage = "Hang onto your butt, we're heading
to www." + site + "!";
break;
case "1":
// this one too..
case 1:
randomMessage = "Destinatio n: www." + site;
break;
case "2":
case 2:
randomMessage = "www." + site + "? Energize!";
break;
case "3":
case 3:
randomMessage = "Are you ready to visit www." + site
+ "? Here we go!";
break;
case "4":
case 4:
randomMessage = "So, you think www." + site + " is
better?! Take a look";
break;
}
alert(randomMes sage);
}
</script>
</title>
</head>
<body onLoad="loadPag e();">
<h1 align="center">
Here are a few of my favorite links
</h1>
<hr />
<a href="http://www.slashdot.or g" onMouseOver="mo useIsOver
('slashdot.org' );" onMouseOut="mou seIsOut('slashd ot.org');"
onClick="mouseH asClicked('slas hdot.org');">
Slashdot
</a>
<!-- div to display the message -->
<div id="msgArea"></div>
</body>
</html>
Hope this help.

May 25 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
7159
by: Marc | last post by:
Hi all, I am trying to write an application where I need the ability to open an Excel spreadsheet and do basic read/write, insert rows, and hide/unhide rows. Using win32com I have been able to get the basics down as well as some examples displaying how to simply read and write. But the next step appears exponential. I haven never done...
4
4797
by: Derek | last post by:
Hi, I've built a rather large CGI that dumps a lot of data and a fairly complex javascript app out to the client's browser. Granted this may be poor style according to someone web design philosophy but that is the way things need to work for now here. The problem I'm having is that it appears that the browsers (IE, mozilla and netscape) are...
5
1214
by: Mitch | last post by:
Built a basic word game for the kids, using if, else , string input, etc, its kinda cool I would like to put in some bmp or jpg to color it up a bit. The books i have do not show how to display a picture, Please let me know how to simply put in picture files into my program TIA
2
3434
by: Carole MacDonald | last post by:
There have been lots of posts on this topic, but I haven't been able to apply any of the suggestions to my situation. I have an .aspx page with a form on it that has several submit buttons on it. Clicking a button will cause a web service action that returns XML. I would like to display this XML response on the page with the form. I know...
5
2205
by: Robert | last post by:
Hello Accessors I have some reports created in Access that are very good for what they do. However, it seems to me that when you are displaying information you don't need to print out that a printer-friendly report is not the best way to go. So, I tried converting one of my Access reports to an Access form. I selected the continuous view...
14
3083
by: alwayshouston | last post by:
Hi All! I am working on this very small database and I am confused in the designing a simple form. I only have three tables in the database. First Table: tblExpense Columns: ExpenseID ; ExpenseType Data: 1 ; FOOD 2 ; AIRLINE 3 ; FARE
15
2131
by: shaqattack1992-newsgroups | last post by:
Hello Everyone, Let me explain my problem. I have included 2 dashes between each pair of records to make it easier to see what goes together. In reality, it is just a long list of results from my query. Contract--------QTY--------COMPONENT--------LENGTH-------PCS
0
5532
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
2
3140
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button then the calender gone actually i want if i click outside off the calender then it should me removed ..How kan i do this ... Pls inform me as early...
19
3295
by: Ganesh J. Acharya | last post by:
Hi there, I want to redesign my website and make that look professional. I made this about 6 years ago with very little knowledge of internet. Today I am getting about 4000 visitors a day for the same. What are the things I need to keep in my mind when doing this process.
0
7406
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7660
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7813
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7431
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5976
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5337
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4949
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3457
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1888
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.