Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2004
    Location
    bristol
    Posts
    3,799
    Tokens
    0

    Latest Awards:

    Default [JavaScript] Basic JavaScript tutorial

    I've written this tutorial to be used as an introduction to someone without a vast amount of JavaScript knowledge.
    Through this tutorial you will be shown how to create a drop-down menu, which when used allows the user to change the background colour of the page.


    Step 1.
    I've created the basic structure of the HTML page, this includes the drop-down menu and other neccessary HTML.
    HTML Code:
    <html>
    <head>
    <title>Example</title>
    
    <script type="text/JavaScript">
    <!--Begin
    
    //-->
    </script>
    
    </head>
    <body>
    <fieldset>
     <legend>Background colour</legend>
      <form name="colour_change">
       <select onChange="" name="colour">
        <option value="red">Red</option>
        <option value="green">Green</option>
        <option value="blue">Blue</option>
        <option value="yellow">Yellow</option>
       </select>
     </form>
    </fieldset>
    </body>
    </html>
    Step 2.
    Add this function to the JavaScript. This function (when called) changes the background to the variable "colour".
    Code:
    function change_colour(colour) {
    document.bgColor = colour;
    }
    Step 3.
    The folowing code needs to be placed in the "onChange" attribute (inside the "select" element).
    Code:
    change_colour(document.colour_change.colour.value)
    If followed correctly you should end up with the following example.
    http://joshjh.pwp.blueyonder.co.uk/b...und_change.htm
    kinda quit.

  2. #2
    Join Date
    Aug 2005
    Location
    Newcastle
    Posts
    1,417
    Tokens
    0

    Latest Awards:

    Default

    Very nice, But instead of just having "Red" (etc) Couldn't you just enter a Hex or an image?

    - Craig.
    Last edited by craigg.; 19-03-2006 at 09:09 PM. Reason: typo



  3. #3
    Join Date
    Aug 2004
    Location
    bristol
    Posts
    3,799
    Tokens
    0

    Latest Awards:

    Default

    You can change any style, just modify the function as needed.

    [Example of changing the page margin]
    Code:
    function change_margin(w) {
    document.style.margin = w+','+w+','+w+','+w;
    }
    HTML Code:
    <option value="1">1 PX</option>
    kinda quit.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •