iLTC Home
Bookmark iLTC!
iLTC Google Boards

Categories

Perl
  • Perl Tutorials Beginners

    Javascript
  • Javascript Tutorials
  • Javascript Tutorials Beginners

    HTML
  • HTML Tutorials



  • iLoveTheCode.com
    Javascript > Javascript Tutorials How To Easy > Passing an Argument or Variable to a Javascript

    Passing an Argument or Variable to a Javascript



    This sounds harder than it is. We are going to pass an argument to a function.

    We will name our function sayGoodbye() because we want it to sound kind of sad.

    Here is our new function for the top of our HTML document.

    function sayGoodbye(what) {
    alert(what);
    }

    The word "what" can be any word as long as it is the same in both places. (The alert() method is built-in to Javascript and it opens an alert box in your browser.)

    Create a link that calls our new function. (Use single quotes because we are already inside double quotes.)

    <a href="http://google.com" onClick="sayGoodbye('Tell Google I said Hi');return true">Google</a>

    When we click this link, whatever text is in the single quotes is passed into our variable "what". In this case we print the "what" variable in an alert box. We could have printed it to the browser page if we were so inclined and we hadn't just sent our user to Google.


    Copy and Paste Javascript (two sections):

    Top of HTML:

    <script type=text/javascript>
    <!--
    function sayGoodbye(what) {
    alert(what);
    }
    -->
    </script>

    Link:

    <a href="http://google.com" onClick="sayGoodbye('Tell Google I said Hi');return true">Google</a>


    In the link, the "return true" means go to the link that is being clicked on. "return false" would stop from going to the link.


    Passing Argument - See in Action (new window)


    Click HERE to comment or discuss at iLoveTheCode GOOGLE Group
    Previous Article: Opening an Alert Box in Javascript
    Next Article: PRINT to Browser with document.write Command in Javascript





    HTML, XHTML, and CSS, Si...HTML, XHTML, and CSS, Sixth Edition ...

    Elizabeth Castro

    New $23.09

    Head First HTML with CSS...Head First HTML with CSS & XHTML

    Eric Freeman, Elis...

    New $26.39

    Dreamweaver CS3Dreamweaver CS3

    David McFarland

    New $29.69

    Information Architecture...Information Architecture for the Wor...

    Louis Rosenfeld, P...

    New $26.39

    Head First AjaxHead First Ajax

    Rebecca Riordan

    New $29.69

    Beginning Joomla!Beginning Joomla!

    Dan Rahmel

    New $29.69

    JavaScriptJavaScript

    David Flanagan

    New $31.49

    Struts 2 in ActionStruts 2 in Action

    Don Brown, Chad Da...

    New $29.69


    Of Interest:
  • Use the Perl PRINT FUNCTION
  • Write a WHILE LOOP in Perl, Carefully
  • Get the Length of a Word or String in Perl
  • Add, Subtract, Multiply, and Divide in Perl
  • Get String Length with Javascript
  • Use onLoad in Body Tag with Javascript
  • Use onLoad to Call More than One Function with Javascript
  • Increment a Variable in Javascript
  • Make a Line Return Using HTML
  • HTML Title Tag
  • Make Italic Text Using HTML
  • HTML Link

  • More Articles:
  • Getting Server Time in Perl
  • Add to the Beginning of an Array with Unshift in Perl
  • Add, Subtract, Multiply, and Divide in Perl
  • Get the Length of a Word or String in Perl
  • onClick Javascript
  • Use onMouseOut in Javascript
  • Use innerHTML to Change Text on a Page
  • Reading Cookies using Javascript
  • HTML Subscript Text
  • HTML Tags
  • HTML Center
  • HTML Image

  • Search iLTC w/ Google





    Recent Articles

  • Javascript Focus Form Field
  • Javascript Lowercase Text
  • Javascript Uppercase Text
  • Javascript Superscript Text
  • Javascript Subscript Text
  • Make Text Blink Using Javascript
  • Make a String into a Link in Javascript
  • Javascript Italics Text
  • Javascript Bold Text
  • Javascript Redirect
  • HTML Frames
  • HTML Color Chart
  • HTML Link
  • Javascript Status Bar








  • Perl Programming - Javascript Programming - Maybe Some PHP - Free Scripts - ILoveTheCode
    All Content © 2006 iLoveTheCode.com


    Contact Chris | About this Site


    581,407
    Counter by iLoveTheCode.com


    Last Modified: Friday, 23-Jun-2006 07:23:17 EDT