homepage Welcome to WebmasterWorld Guest from 54.204.182.118
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Javascript not running with HTML code
alleria21



 
Msg#: 4514383 posted 9:39 pm on Oct 31, 2012 (gmt 0)

Hello to all web loverzzz.
had a tiny little problem concerning this code.

HTML Code

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>The American Eggplant Society</title>
</head>
<body>
<h1>The American Eggplant Society</h1>
<p>Welcome to our site. Unfortunately, it is still
under construction.</p>
<p>We last worked on it on this date:
<script type="text/javascript">

document.write(document.lastModified);

</script>
</p>
</body>
</html>

Been using Mozilla along with IE8 and chrome but cant figure out why scripts are not running at all :P

 

birdbrain

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 4514383 posted 9:59 pm on Oct 31, 2012 (gmt 0)

Hi there alleria21,

try it like this...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<title>The American Eggplant Society</title>

<script type="text/javascript">
function init(){
document.getElementById('last-modified').firstChild.nodeValue=document.lastModified;
}
window.addEventListener?
window.addEventListener('load',init,false):
window.attachEvent('onload',init);
</script>

</head>
<body>

<h1>The American Eggplant Society</h1>
<p>
Welcome to our site. Unfortunately, it is still
under construction.
</p><p>
We last worked on it on this date:
<span id="last-modified">&nbsp;</span>
</p>

</body>
</html>


birdbrain

alleria21



 
Msg#: 4514383 posted 10:23 pm on Oct 31, 2012 (gmt 0)

Thanks birdbrain! works like a charm :P
cant imagine what went wrong with previous code though :/ and the one i posted earlier with the CSS im thinking it might be an issue with windows version or bit system maybe :P

birdbrain

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 4514383 posted 11:12 pm on Oct 31, 2012 (gmt 0)

No problem, you're very welcome. ;)



birdbrain

Fotiman

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4514383 posted 2:59 am on Nov 1, 2012 (gmt 0)

document.write does not work with XHTML. The bigger question you might want to ask yourself is should I be using XHTML? For 99% of developers, the answer is no. See this old thread:
[webmasterworld.com...]

alleria21



 
Msg#: 4514383 posted 2:11 pm on Nov 1, 2012 (gmt 0)

hmm it seems that xhtml has compatibility problems ...
Well then is it ok if i stick to HTML 4.01 Strict cuz im a little afraid of what are the advantages/disadvantages of doing so .but if todays developers use HTML 4.01 (at least till HTML 5 takes on) then it is ok :P

phranque

WebmasterWorld Administrator phranque us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



 
Msg#: 4514383 posted 2:18 pm on Nov 1, 2012 (gmt 0)

i would suggest using the HTML5 DTD and HTML 4.01 compatible markup.

Fotiman

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4514383 posted 2:49 pm on Nov 1, 2012 (gmt 0)

Yeah, use an HTML 5 DOCTYPE, even if you don't use any of the new HTML 5 features. HTML 5 is a superset of HTML 4.01, so any valid HTML 4.01 document can use an HTML 5 doctype. Also, the HTML 5 DOCTYPE is so much easier to remember. :)
<!DOCTYPE html>

Fotiman

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4514383 posted 2:54 pm on Nov 1, 2012 (gmt 0)

Also, avoid using document.write, as it's generally considered bad practice to use it. Instead, use DOM methods to modify values and/or insert new content. birdbrain's example above uses the nodeValue to change the value of an existing node. Other options could include creating a new node and using appendChild or replaceChild to add it to the document.

alleria21



 
Msg#: 4514383 posted 5:08 pm on Nov 1, 2012 (gmt 0)

:D Okay from now on i forget about xhtml :Pp thanks so much guys!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved