iLTC Home
Bookmark iLTC!
iLTC Google Boards

Google Groups
Receive The Code in Email!



Categories

Perl
  • Perl Tutorials Beginners

    Javascript
  • Javascript Tutorials
  • Javascript Tutorials Beginners

    HTML
  • HTML Tutorials



  • Pass the Javascript, please...
    143,003

    iLoveTheCode.com
    Javascript > Javascript Tutorials How To Easy > Use onClick in Javascript

    Use onClick in Javascript



    There are a couple of ways to use onClick in Javascript...

    You can write the javascript right into the link tag or you can call a function located elsewhere in your code.

    First, we'll write the code right into the link:

    <a href="#" onClick="javascript:window.open('http://google.com');return false">Google</a>

    -After the onClick tag, we enclose our entire javascript code in double quotation marks.
    -We start with the javascript: to tell the browser we have javascript code coming up.
    -We use javascript's built-in window.open method to open Google in a new window. Since we are inside double quotes, we use single quotes around our Google address.
    -We return false so the browser won't use the href tag. If we return true the main browser window would go to the url in the href tag.


    Using onClick to call a function is similar and fairly easy:

    function goGoogle() {
    window.open('http://google.com');
    }

    <a href="http://yahoo.com" onClick="javascript:goGoogle();return true">Google</a>

    -First we created our function goGoogle.
    -Instead of writing our code in the onClick tag, we just called our newly created function.
    -This time we returned true so the main browser will go to Yahoo.



    Free Copy and Paste Javascript Code:

    <script type="text/javascript">
    <!--

    function goGoogle() {
    window.open('http://google.com');
    }

    -->
    </script>

    <a href="#" onClick="javascript:window.open('http://google.com');return false">Google 1</a>
    <a href="http://yahoo.com" onClick="javascript:goGoogle();return true">Google 2</a>



    Resources:
    Create a Function in Javascript
    Call your Function in Javascript
    Opening a REMOTE WINDOW in Javascript


    Click HERE to comment or discuss at iLoveTheCode GOOGLE Group
    Previous Article: Increment a Variable in Javascript
    Next Article: Use OnMouseOver in Javascript





    JavaScriptJavaScript

    David Flanagan

    New $31.49

    Bulletproof Web DesignBulletproof Web Design

    Dan Cederholm

    New $23.99

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

    Eric Freeman, Elis...

    New $23.99

    Learning Web DesignLearning Web Design

    Jennifer Niederst ...

    New $26.99

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

    Elizabeth Castro

    New $23.09

    HTML & XHTMLHTML & XHTML

    Chuck Musciano, Bi...

    New $29.99

    CSSCSS

    Eric Meyer

    New $29.69

    Dreamweaver CS3Dreamweaver CS3

    David McFarland

    New $29.69


    Of Interest:
  • And, Or, Equal, Not Equal, Greater Than, Less Than in Perl
  • Passing a Variable or Value to a Subroutine in Perl
  • Create or Put Items into an Array in Perl
  • To Sort an Array in Perl
  • Passing an Argument or Variable to a Javascript
  • Use OnMouseOver in Javascript
  • Select All or Highlight Text Fields and Textareas Using Javascript
  • Get String Length with Javascript
  • Make Italic Text Using HTML
  • HTML Superscript Text
  • HTML Title Tag
  • HTML Center

  • More Articles:
  • INCREMENT and DECREMENT a Variable in Perl
  • Matching with a Regular Expression, REGEX, in Perl
  • Matching at the Beginning and End
  • Substitute in Perl
  • onClick Javascript
  • Formatting Time in Javascript
  • Focus a Window with self.focus in Javascript
  • Opening an Alert Box in Javascript
  • Increment a Variable in Javascript
  • HTML Font Code
  • HTML Forms
  • HTML Body Tag
  • HTML Codes

  • 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


    439,768
    Counter by iLoveTheCode.com


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