eHow launches Android app: Get the best of eHow on the go.

How To

How to Write Java Script

Contributor
By Jackson Lewis
eHow Contributing Writer
(0 Ratings)

JavaScript is the common name that refers to the ISO standard ECMAScript, which is used for client side programming for web pages. Designed to be easy to use and implement, JavaScript can be authored using a text editor and can be included in the header of a web page or saved as a stand-alone file that the web page accesses. Web authors use JavaScript to make their web pages more dynamic and interactive. Specific uses for JavaScript include adding special effects to your web page, customizing pages based on user selections and performing calculations.

Difficulty: Moderately Easy
Instructions

Things You'll Need:

  • Text editor
  1. Step 1

    Start a new web page and include the opening and closing script tags in the web page header. The web page can be authored in a text or web page editor such as Adobe's DreamWeaver. The code to do this is:
    <head>
    <script>
    </script>
    </head>

  2. Step 2

    Define a JavaScript method called MsgBox, which will accept a text string as an input argument within the opening and closing script tags. Within the MsgBox method, invoke the JavaScript alert method using the text string that is passed to the method as the data to display. This method will be invoked when the user clicks a form entry box that will be defined in a later step. The code to do this is:
    <script>
    function MsgBox (textstring)
    {
    alert (textstring)
    }
    </script>

  3. Step 3

    Create the HTML code to accept a text input from the user that will be passed to the JavaScript method MsgBox. When the user selects the submission button, the text will be displayed to the user in an alert box. The code for the form is:
    <body>
    <FORM>
    <INPUT NAME="text1" TYPE=Text>
    <INPUT NAME="submit" TYPE=Button VALUE="Show A Javascript Alert" onClick="MsgBox(form.text1.value)">
    </FORM>
    </body>
    </html>

  4. Step 4

    Save the webpage and view it in your web browser. The data input into the text field will display in a JavaScript alert when you click the submission button.

Subscribe

Post a Comment

Post a Comment

Related Ads

  • Have you done this? Click here to let us know.
I Did This
Get Free Computers Newsletters

Copyright © 1999-2009 eHow, Inc. Use of this web site constitutes acceptance of the eHow Terms of Use and Privacy Policy .   en-US Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License. † requires javascript

eHow Computers
eHow_eHow Technology and Electronics