/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Pass values to Function to display in browser

Hi all –

Trying to pass some strings to the whatToWrite function in the code below.
I am not receiving anything in the Firefox browser window except the stuff in <h2>

Do I need an event handler to make this work?
Seem it should work w/o EH

Thanks much
Winston

[CODE]<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”>
<html xmlns=”http://www.w3.org/1999/xhtml”>

<head>
<title>Lesson 2 – Looping and Functions</title>
<script langauge=”Javascript” type=”text/javascript”>
<!– Hide script from older browsers
<!– Function to write a message, text passed from scripts in the body of the document –>
function whatToWrite(message) {
document.write(message)
ducoument.write(“<br />”)
}

// End hiding script from older browsers –>
</script>
</head>
<body bgcolor=”#FFFFFF”>
<h2>
GilaMonster<br />
CIS 166AA<br />
Functions and Loops<br />
Lesson 2<br />
<hr />
</h2>
<script langauge=”Javascript” type=”text/javascript”>
<!– Hide script from older browsers
<!– For loop to write a message 5 times. Calls a function and passes a string to the function –>
document.write(<br />”)
for(i=1; i<6; i++){
whatToWrite(“An example of a for loop…”)
}

<!– While loop to write a message 5 times. Calls a function and passes a string to the function –>
document.write(<br />”)
i = 0
while (i < 6){
whatToWrite(“This is being written from a while loop…”)
i++
}

<!– Do..While loop to write a message 5 times. Calls a function and passes a string to the function –>
document.write(<br />”)
i = 0
do {
whatToWrite(“Finally, an example of a Do..While loop…”)
i++
}
while(i < 6)

// End hiding scripr from older browsers –>
</script>
</body>
</html>[/CODE]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERJun 14.2008 — Does it work better when you fix:

ducoument.write("<br />");

?
Copy linkTweet thisAlerts:
@Declan1991Jun 14.2008 — And you should never use HTML comments (<!-- -->) inside a script tag. Use Javascript comments // or /* */ and there is no need to "hide script from old browsers", the only thing that does is actually have it actually ignored in the future.
Copy linkTweet thisAlerts:
@GilaMonsterauthorJun 14.2008 — Thanks guys,

Works great now.?

Final code below.

Thanks again,

Winston

[CODE]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Lesson 2 - Looping and Functions</title>
<script langauge="Javascript" type="text/javascript">

//Function to write a message, text passed from scripts in the body of the document -->
function whatToWrite(message) {
document.write(message)
document.write("<br />");
}
</script>
</head>
<body bgcolor="#FFFFFF">
<h2>
GilaMonster<br />
CIS 166AA<br />
Functions and Loops<br />
Lesson 2<br />
<hr />
</h2>
<script langauge="Javascript" type="text/javascript">

//For loop to write a message 5 times. Calls a function and passes a string to the function
document.write("<br />");
for(i=1; i<6; i++){
whatToWrite("An example of a for loop...")
}

//While loop to write a message 5 times. Calls a function and passes a string to the function
document.write("<br />");
i = 0
while (i < 5){
whatToWrite("This is being written from a while loop...")
i++
}

//Do..While loop to write a message 5 times. Calls a function and passes a string to the function
document.write("<br />");
i = 0
do {
whatToWrite("Finally, an example of a Do..While loop...")
i++
}
while(i < 5)

</script>
</body>
</html>[/CODE]
×

Success!

Help @GilaMonster spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...