69 users online (0 members and 69 guests)  

Thread: HTML Function


  Results 1 to 3 of 3

Related

  1. Adding search function to a HTML website    Forum: HTML Forum
    Replies: 5
  2. Replies: 4
  3. Replies: 1
  4. change html-text with a js-function    Forum: Javascript Forum
    Replies: 1
  1. #1
    jimwest's Avatar
    New User

    Status
    Offline
    Join Date
    May 2007
    Posts
    1

    HTML Function

    Hello,
    I am new to HTML and i would like to know how to write a function in HTML this is what i did i used javascript it work fine when i use javascript code inside the function, but when i use HTML code i got "Error on page" this is what i am looking for
    HTML Code:
    <html>
    <head>
      <script type = "javascript">
        function = "fun1()" { 
          <p>This is a test</p> 
        } 
      </script>
    </head>
    <body>
      <form> 
        <input type = "button" value = "Fun1" onclick="fun1()" /> 
      </form> 
      </body>
    </html>
    Also can i call the function whithout using button???
    Any help is a big help thank you
    Last edited by DeadMeatGF; 05-03-2007 at 10:36 AM. Reason: Added Code tags

  2. #2
    vinyl-junkie's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    721

    Re: HTML Function

    I just finished taking a javascript class. Let's see if I learned anything from it.

    Code:
    <html>
    <head>
      <script type="text/javascript">
        function fun1() { 
          document.write("<p>This is a test<//p>");
        } 
      </script>
    </head>
    <body>
      <form> 
        <input type="button" value="Fun1" onclick="fun1()" /> 
      </form> 
      </body>
    </html>
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more

  3. #3
    coothead's Avatar
    bald headed old fart

    Status
    Offline
    Join Date
    Aug 2003
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    732

    Re: HTML Function

    Hi there jimwest,

    and a warm welcome to these forums.
    ...can I call the function without using button
    Yes, like this...
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <style type="text/css">
    #fun {
        font-family:verdana,arial,helvetica,sans-serif;
        font-size:18px;
        color:#600;
        text-align:center;
     }
    </style>
    
    <script type="text/javascript">
    function fun1() {
       document.getElementById('fun').firstChild.nodeValue='This is a test.';
     }
    window.onload=fun1;
    </script>
    
    </head>
    <body>
    
    <div id="fun">&nbsp;</div>
    
    </body>
    </html>
    Also note that document.write() is deprecated. Instead use document.getElementById()



Tags for this Thread