views:

32

answers:

4

If i add the Js Script above This Line <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; Then CSS Is not working. Is There is any way to solve this issue

<script type="text/javascript">
<?php  $data3  = getmaildata(); ?>
var collection = [<?php echo  $data3; ?>]; 
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org  /TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>.:: sample ::.</title>
<link rel="stylesheet" href="css/stylesheet.css" type="text/css">
A: 

<script> tags are usually placed in <head> or just before </body>, I don't know if it's related but your code is still invalid.

MatTheCat
+2  A: 

A script element can appear in the head or in the body, it can't appear before the Doctype and no element can appear outside the root element (<html>).

If the Doctype (with a couple of provisos which don't apply in this case) isn't the very first thing in a document then browsers will enter Quirks mode (and emulate bugs seen in older browsers with CSS and DOM handling).

There is no way around this (that is well supported by browsers), so just write valid code and don't try to put a script element somewhere that it isn't allowed.

David Dorward
I include the php file in the first line of the program,its working fine,if i add the php file that has javascript statement then only the css is not working .I must include that script in my first line execution in my code .Is there Is any other way to do this .Please Guide me
Meena
No, there isn't. Refactor your PHP so you don't have a simple include that does both HTTP header stuff and content generation stuff. Splitting concerns up according to the MVC pattern is probably a good idea.
David Dorward
If i remove the Dtt in my document other css are not working,. how to include the style sheet without including the DTT.
Meena
You **need** the Doctype to trigger Standards mode so that you don't have wildly inconsistent browser behavior. As I said before, refactor your PHP so it doesn't prevent you from including the Doctype in the proper place.
David Dorward
A: 

What happens if you put the SCRIPT element in its proper place, inside the HEAD section or in the BODY? Also, I don't know what $data3 contains, but if it's a string and not an integer for instance, then it should be encapsulated in quotation marks.

methode
`<script>` elements are equally valid in the `<body>`.
Tim Down
True, corrected.
methode
A: 

The doctype declaration should be the very first thing in an HTML document, before the tag.

The doctype declaration is not an HTML tag; it is an instruction to the web browser about what version of the markup language the page is written in.

The doctype declaration refers to a Document Type Definition (DTD). The DTD specifies the rules for the markup language, so that the browsers can render the content correctly.

http://www.w3schools.com/tags/tag_DOCTYPE.asp

Cipi
*sigh*, more half truths from W3Schools.
David Dorward