Results 1 to 3 of 3

Thread: Multiple methods in a single event?

  1. #1

    Thread Starter
    Hyperactive Member tomcatexodus's Avatar
    Join Date
    Feb 2001
    Posts
    372

    Multiple methods in a single event?

    If upon clicking a button I wanted to have the text onpage turn blue, and the background turn red, what would I do?

    Code:
    <html>
    <body>
    Sample Text<br>
    <button onclick="document.fgColor='blue';">Blue</button>
    </body>
    </html>
    I can make the text turn blue... but simultaneously the page turn red?
    IWS

  2. #2
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Multiple methods in a single event?

    Seperate 2 statements or functions using semi-colon (;).

    in you code, change the button's tag with this:
    HTML Code:
    <button onclick="document.fgColor='blue';document.bgColor='red';">Text 2 Blue, Back 2 Red</button>
    Show Appreciation. Rate Posts.

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Multiple methods in a single event?

    Don't use event handler attributes; keep scripting and structure separate.

    The proper way to use events is to use addEventListener(), in proper browsers; attachEvent(), in IE.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width