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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script does not execute when doctype is specified. 1

Status
Not open for further replies.

jfdabiri

MIS
Feb 27, 2007
282
US
hi,
i have a webpage (asp/vbscript/java). it has a java edit routine that is supposed to prompt user for errors before going to the next page. my script does not execute if this heading is on top of the page's html code:
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "if i take this line out, the script executes. what could be in this line to prevent the script from running? what does this line do? can i omit it?
thanks.
 
What do you mean your script doesn't run? Are you talking about the server-side ASP or script executed by the browser?

That doctype line alerts the browser to which one of the many subtle variations of html/xhtml should be used when rendering your page. If your HTML is pretty standard then it shouldnt really matter but the final judge is how does your page look in IE, Firefox, and any other browser you want to support... so it is a good policy to use a doc type and that is especially true if it really matters the exact details of how your page appears but you can usually live without it...
 
thanks sheco.
i have a script within the html page. like this:
Code:
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]

<html>
<head>  
<title>solutions</title>
<meta NAME="description" CONTENT="solutions, assistance">
<meta NAME="keywords" CONTENT="solutions, recovery">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> 
<meta name="Microsoft Border" content="none">

when i take this out and just leave <html> and <head>
the script runs, otherwise the script will not run and keep going to the next page.
what could be causing this?
 
what could be causing this?

I'll bet donuts the XHTML declaration is.

From the specification: "In XHTML, the script and style elements are declared as having #PCDATA content. As a result, < and & will be treated as the start of markup, and entities such as &lt; and &amp; will be recognized as entity references by the XML processor to < and & respectively. Wrapping the content of the script or style element within a CDATA marked section avoids the expansion of these entities."

You have to wrap the script to have a well formed document.

<script type="text/javascript">
<![CDATA[
... unescaped script content ...
]]>
</script>

I would just change your declaration- you aren't using XHTML anyway because your meta tags aren't well formed.

Try using:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
Things should run then.

Chocolate iced, please.
 
When you say
...unescaped content
do you mean that any escape characters in your script should be stripped out? For example, I might use /" within the java script.

Thanks for clarifying this.
 
The reason I ask is because the HTML validator threw an error when I had some dynamic javascript running in the page. I enclosed this in the PCDATA tag, yet it still throws the same error. I have quite a bit of escaped content within the script.
 
Go Terps- Is it the case that the script executes correctly it is just the validator throwing an error? I'm guessing it is just the validator.

I think I remember reading something about having to validate XHTML pages without scripting elements in there to get them to validate but I don't remember where I read it. I do know that 1) it starts to get over my head reallly fast and 2) it starts to get away from an ASP forum really fast.

The W3C recommendations on the XHTML spec say you should use external scripts if your script uses <, &, ]]>, or --. I think if you throw your script external, you might have better luck validating a page.

I also think if you have a script that runs and it is just the validator throwing an error I would go on and forget about it.

HTH.
 
bigred,
that was it. i removed it and re-did it. it ran fine.
thanks a lot.
cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top