Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   JavaScript and Client-Side Browser Scripting (http://www.programmingforums.org/forum23.html)
-   -   Hello in JavaScript (http://www.programmingforums.org/showthread.php?t=2275)

Dietrich Feb 15th, 2005 2:24 PM

Hello in JavaScript
 
Can anyone give me a "Hello Earth!" in JS?

EdSalamander Feb 15th, 2005 6:27 PM

:

<script language="JavaScript" type="text/JavaScript">

  document.write("Hello Earth!");
  alert("Hello Mars!");
  document.getElementById('helloDiv').innerHTML = "Hello Pluto!";

</script>

<br>

<div id="helloDiv"></div>


Ooble Feb 16th, 2005 8:22 AM

Remember that document.write doesn't work in XHTML though - don't ask me why.

Dietrich Feb 17th, 2005 1:29 AM

Quote:

Originally Posted by EdSalamander
:

<script language="JavaScript" type="text/JavaScript">

  document.write("Hello Earth!");
  alert("Hello Mars!");
  document.getElementById('helloDiv').innerHTML = "Hello Pluto!";

</script>

<br>

<div id="helloDiv"></div>


Thanks EdSalamander!
Now let's bring in a little of Peter Schilling's Major Tom song!

Ooble Feb 17th, 2005 12:35 PM

Oooh... just noticed an error. Not an important one, but an error all the same. In the type attribute (not the language attribute) of the <script> tag, "JavaScript" should be in lowercase.

tempest Feb 20th, 2005 5:31 PM

Quote:

Originally Posted by Ooble
Remember that document.write doesn't work in XHTML though - don't ask me why.

Easy fix is...

:

document.write = function(str) { document.outerHTML += str; }

Btw the language attribute of script is deprecated, to keep up with standards use...
:

<script type="text/Javascript">
    //<![CDATA[
        /* .. your code here .. */
    //]]>
</script>



All times are GMT -5. The time now is 5:38 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC