The forums have permanently moved to This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 6 of 6

Thread: JAVASCRIPT onClick, which button was clicked?

  1. #1

    JAVASCRIPT onClick, which button was clicked?

    I have something like this:
    HTML Code:
    <tr><td>Local</td><td id="localTime"></td><td><input type="button" value="Get Time" onClick="getServerTime()" /></td></tr>
    <tr><td>New York</td><td id="newyorkTime"></td><td><input type="button" value="Get Time" onClick="getServerTime()" /></td></tr>
    <tr><td>Tokyo</td><td id="tokyoTime"></td><td><input type="button" value="Get Time" onClick="getServerTime()" /></td></tr>
    All of those buttons have an onClick="getServerTime()"

    But how do I find out WHICH BUTTON was clicked? Is there a variable? a method?
    All of the buttons call getServerTime, but I need to know which button was clicked.

    Thanks in advance.

    "You are playing a very dangerous game"
    "Change always is"

    Creativo Development

  2. #2
    This might be the easiest solution.
    instead of
    Last edited by Templarian; May 26th, 2009 at 01:08 PM.

    Join #kirupa | Click the under my Username | CL | Jeff

  3. #3
    You can pass in this into your functions and that will represent the button being clicked. But I'm going to have to go with Temp for the appropriate approach to your problem.

  4. #4
    also ...
    is the proper, non-1990s way, to write it. not
    Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
    Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.

  5. #5
    the 1990's - good times

  6. #6

    function getServerTime(obj) {


    document.onclick = function(e) {
    var target = (window.event) ? event.srcElement :;
    if ( target == document.getElementById("somebutton1") ) {
    // more code for button 1
    } else if ( target == document.getElementById("somebutton2") ) {
    // more code for button 2
    AS2 / AS3 / JS / JQUERY / (X)HTML / HTML5 / CSS / CSS3 / PHP

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012