beginner question

B

beenben

when I just have the alert on onload it works but I can't get it to
work when I've also got an alert on unLoad. What am I doing wrong??

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">



<head>
<script type="text/javascript">
function surveyQ(){alert("Please take our Customer Service Survey.");}
return true;



function thanks(){alert("We appreciate you opinions!"); } return true;



</head>


<body>
onload="surveyQ()";

onUnload="thanks()";

</body>

</script>
</html>
 
E

Evertjan.

beenben wrote on 02 mrt 2008 in comp.lang.javascript:
when I just have the alert on onload it works but I can't get it to
work when I've also got an alert on unLoad. What am I doing wrong??

[please leave al the crap out that has nothing to do with your Q]
function surveyQ(){alert("Please take our Customer Service Survey.");}
return true;
function thanks(){alert("We appreciate you opinions!"); } return true;

Thanks to your bad visual formatting you do not see your mistakes.

I will reformat:

function surveyQ() {
alert("Please take our Customer Service Survey.");
};
return true;

function thanks() {
alert("We appreciate you opinions!");
};
return true;

Looking for the error text and error line number can help you
if you do not see the bugs yet.
 
T

Thomas 'PointedEars' Lahn

beenben said:
when I just have the alert on onload it works but I can't get it to
work when I've also got an alert on unLoad. What am I doing wrong??

Maybe using `onUnload' instead of `onunload'. XHTML is case-sensitive.
[...]
<body>
onload="surveyQ()";

onUnload="thanks()";

Maybe using `onUnload' instead of `onunload'. XHTML is fully case-sensitive.

See also:

http://www.w3.org/TR/xhtml1/
http://hsivonen.iki.fi/xhtml-the-point/
http://hixie.ch/advocacy/xhtml
http://www.spartanicus.utvinternet.ie/no-xhtml.htm


PointedEars
 
M

Mango

Hi :)

Great start; you are almost there. A few notes.

1) You have a couple of "return true;" that are outside your functions.
2) Your closing </script> tag was in the wrong place. <body> cannot be
inside <script>. Make sure to always close tags in the reverse order
you open them.
3) Your onload and onunload attributes were in the wrong place. Also
note that for XHTML, attributes should be in lower case. Use onunload
instead of onUnload.

This worked for me:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
<head>
<script type="text/javascript">
function surveyQ(){
alert("Please take our Customer Service Survey.");
}
function thanks() {
alert("We appreciate you opinions!");
}
</script>
<title>Test page</title>
</head>
<body onload="surveyQ();" onunload="thanks();">
<p>Content goes here...</p>
</body>
</html>

Cheers,
Mango
 
M

Mango

Evertjan. said:
[please leave al the crap out that has nothing to do with your Q]

Actually, the "crap" had everything to do with his question. For
Thanks to your bad visual formatting you do not see your mistakes.

I was able to read it perfectly well.
I will reformat:

It still doesn't work ;) He asked a perfectly reasonable question. If
you're going to mock him, at least do it right :D
 
E

Evertjan.

Mango wrote on 02 mrt 2008 in comp.lang.javascript:
Evertjan. said:
[please leave al the crap out that has nothing to do with your Q]

Actually, the "crap" had everything to do with his question. For
instance, he left some attributes outside of the <body> tag, which we
would not have known if he posted only the Javascript.

No, that part was not the crap.
I was able to read it perfectly well.


It still doesn't work ;) He asked a perfectly reasonable question. If
you're going to mock him, at least do it right :D

Beside the point,because:
Reformatting shows the error, reformatting is not correcting.
I am not mocking him, though I am tempted to mock you.

I am showing him a way to find the error himself by just looking at the
code, you obviously did not see it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top