views:

97

answers:

6

I have the folowing html. It passes the w3 validator, but my javascript alert does not work. Can anyone see any problems or have any suggestions on how to get it to work?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Company Name™</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />

<style type="text/css">
BODY {background-image: url(images/bg4.jpg); background-repeat:no-repeat; 
background-position:center top;
background-attachment: fixed; }
</style>

<script type="text/javascript">
 alert("HELLO");
</script>

</head>

<body>
<div id="wrapper">
<div id="header">
    <div class="logo">
    <img src="images/fcflogo.png" width="295" height="100" align="left" alt="logo"/>
    </div>

    <div class="header1"><a href="financialprotection.html">100% Financial Protection</a>
    <hr/>
    </div>

    <div class="nav">Home| Flights| Hotels| Villas | CarHire| Attractions| Contact</div>
</div>

<div class="ver1">
    <h2>Can't find what your looking for?</h2></div>
    <div class="enq1"><h2>Enquiry Form</h2></div>

<div class="hor1"><h2>Our Service</h2>
    <a>Company Name are one of the leading independent travel companies specialising in Florida Holidays. We have a wide range of major Charter and Scheduled airlines to choose from as well as over 10,000 Hotel and Villa deals. Our aim is to provide you the customer with a truly fantastic vacation in Florida from start to finish at affordable prices. We are not committed to any airline or Tour operator so are totally committed to finding you the best deal.</a>
</div>

<div class="hor1"><a>FLIGHTS</a></div>
<div class="ver2"><a>HOTELS</a></div>
<div class="ver2"><a>VILLAS</a></div>
<div class="hor1"><a>CAR HIRE</a></div>
<div class="hor1"><a>ATTRACTIONS</a></div>

</div>

<hr/><div id="footer"><a>FOOTER</a></div>

</body>

</html>

EDIT - To all below, I do have javascript turned on, I am using debian with firefox, noScript is disabled, but the alert does not appear, even if I move it to the body.

A: 

Seems to work quite fine.

Matti Virkkunen
It does not work for me at this link.
+1  A: 

For me, your code works, the alert appears. Have you enabled javascript in your browser?

ipsum
A: 

Works fine on FF 3 and IE 8 for me.

Have you disabled JavaScript on your browser by any chance?

vassilis
A: 

The script is never being invoked and that's why it is not alerting anything. Either move that script tag from within head to within body tag of the document. Or enclose it within a function and invoke it from onload attribute of body tag.

Floyd Pink
@downvoter: Thanks for your very unhelpful action
Floyd Pink
@floyd upvoted you to cancel it out as I didnt realise that this had to be done to get it to work
Even in the `head`, the script should run. That's not the placement of the script that occurs the problem.
Török Gábor
A: 

You might want to try clearing your cache to make sure that your browser is loading the file with the alert in it instead of an older, cached copy. If that doesn't work, I'd suggest trying it with Firefox/Firebug and checking for errors in the javascript console. If you're loading the file with AJAX, you'll need to move the script tag to the body of the document. Most of the time AJAX libraries will ignore the HEAD element and only include elements within the BODY tag.

tvanfosson
+3  A: 

First, take out the trade mark. That extended characters is probably killing the closing </title> tag. I"m pretty sure that's your issue.

Failing that, remove every element above the <script> tag and see if it executes. If it does, restore each element one-by-one. Something above the script tag is preventing it from being parsed.

Andrew
Removing the trade mark did it. Not sure why that made it break though...
It's the character encoding. Basically, an extended character is a double-character that's supposed to be single. When the browser gets confused, it will often display the first character (giving you a random squiggle) and combine the second character with the next thing it finds on the page. In this case, `<` in `</title>`. So, in effect, your title tag never closed. Another solution is to make sure that you are saving your file in UTF-8. If say you are using UTF-8 in your `<meta>` but save it in another, you get instant trouble. I'm guessing only Debian+Firefox doesn't correct for this.
Andrew