How to Use a Tag With OnClick

The HTML "OnClick" event triggers when your website users click a button, image or link. You can use the OnClick event to customize the user's browser action. For instance, OnClick lets you open a new window or run some calculations before redirecting the user. It also lets you verify form information or show a confirmation message box. The OnClick event performs these customized functions using JavaScript.

Instructions

    • 1

      Right-click the HTML page you want to edit and select "Open With." Click your HTML editor in the list of programs to load your code and the HTML program simultaneously.

    • 2

      Create the JavaScript function that runs when the user clicks the HTML element. In this example, the JavaScript function displays a message when the user clicks a button:

      function userclicked() {

      alert("Thank you for submitting your information.");

      }

    • 3

      Link the JavaScript function with the HTML element's "OnClick" event. The following code shows you how to use the "OnClick" function to display the message when the user clicks a button:

      <input type="button" OnClick="userclicked()" value="Click here to submit the form">

Related Searches:

References

Comments

Related Ads

Featured