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 > onClick Javascript

    onClick Javascript



    onClick is an easy to use Javascript event handler. Event handlers are used to tell the browser what to do when an event occurs. In this case, onClick is the event. Fairly simple.

    Here's one way to use onClick in a link tag.

    <a href="#" onClick="javascript:alert('Hello!');return false">Say Hi</a>

    -After the onClick Javascript event handler, we enclose our entire javascript code in double quotation marks.
    -We start with javascript: to tell the browser we have javascript code coming up.
    -We use the built-in javascript alert method to open an alert box. Since we are inside double quotes, we use single quotes around our 'Hello!' message.
    -We return false so the browser won't use the href tag. If we return true the browser window would go to the url in the href tag.

    The onClick Javascript event handler is incredibly useful in that it can be used in more than just link tags. It can used in submit buttons, radio buttons, reset buttons as well as checkboxes.

    There are examples of these below and links to even more information about onClick.

    Say Hi


    Free Copy and Paste Javascript Code:

    <a href="#" onClick="javascript:alert('Hello!');return false">Say Hi</a>

    <input type="submit" onClick="javascript:alert('Submit Me!');return false">

    <input type="radio" name="radset" onClick="javascript:alert('Radio Selected!')">

    <input type="checkbox" onClick="javascript:alert('Checkbox Selected!')">



    Resources:
    Javascript Documentation at Sun microsystems
    Use onClick in Javascript to Call a Function


    Click HERE to comment or discuss at iLoveTheCode GOOGLE Group
    Previous Article:
    Next Article: Javascript Alert





    JavaScriptJavaScript

    David Flanagan

    New $31.49

    Struts 2 in ActionStruts 2 in Action

    Don Brown, Chad Da...

    New $29.69

    HTML, XHTML, and CSS All...HTML, XHTML, and CSS All-in-One Desk...

    Andy Harris, Chris...

    New $23.09

    CSSCSS

    David McFarland

    New $23.09

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

    Louis Rosenfeld, P...

    New $26.39

    Learning Web DesignLearning Web Design

    Jennifer Niederst ...

    New $29.69

    CSSCSS

    Eric Meyer

    New $29.69

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

    Eric Freeman, Elis...

    New $26.39

    jQuery in ActionjQuery in Action

    Bear Bibeault, Yeh...

    New $26.39


    Of Interest:
  • Use chmod in Perl
  • Opening and Reading a Directory in Perl
  • Matching at the Beginning and End
  • Redirect to a Different URL in Perl
  • Javascript Bold Text
  • Javascript SetTimeout
  • Javascript Sort - Use Sort on Items in an Array in Javascript
  • Write a For Loop in Javascript
  • HTML Title Tag
  • HTML Font Code
  • HTML Codes
  • Make Text Bold Using HTML

  • More Articles:
  • Putting Two Strings Together, Concatenate
  • Making a Directory Using mkdir in Perl
  • Get the Length of a Word or String in Perl
  • If, Elsif, and Else in Perl
  • Splitting an Array using Javascript
  • PRINT to Browser with document.write Command in Javascript
  • Opening an Alert Box in Javascript
  • Setting a Cookie using Javascript
  • HTML Tags
  • Make a New Paragraph Using HTML
  • HTML Image
  • HTML Body Tag

  • 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,341
    Counter by iLoveTheCode.com


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