• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 12. Working with Forms, Buttons,... > Clicking a Button from Code

Clicking a Button from Code

Using the click method, you can simulate a button click. This method also causes the onclick event to occur. Here’s an example where I’m simulating a click of one button when the user clicks another (if you’re using Netscape Navigator, you’ll need version 6+ to use the <BUTTON> element):

(Listing 12-10.html on the web site)

<HTML> 
    <HEAD> 
        <TITLE> 
            Executing Scripts in Response to User Action 
        </TITLE> 
        <SCRIPT LANGUAGE="JavaScript"> 
            <!--
            function alerter1() 
            { 
                window.alert("You clicked the button!") 
            } 
            function alerter2()
					{
					document.form1.button1.click()
					} 
            // --> 
        </SCRIPT> 
    </HEAD> 

    <BODY> 
        <H1>Executing Scripts in Response to User Action</H1> 
        <FORM NAME="form1"> 
            <INPUT TYPE="BUTTON" ID="button1" ONCLICK="alerter1()" VALUE="Click Me!"> 
            <BR> 
            <INPUT TYPE="BUTTON" ID="button2" ONCLICK="alerter2()" VALUE="Click Me Too!"> 
        </FORM> 
    </BODY> 
</HTML> 

					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint