Is it possible to figure out what html-tag an event was generated for?

Discussion in 'JavaScript' started by blue8sky, Feb 20, 2008.

  1. #1
    Hi )

    For example I have:

    
    <input type="text" name="name" onclick="some_func_1();">
    
    <input type="text" name="phone" onclick="some_func_2();">
    
    Code (markup):
    But I don't want to use a particular event-handler for each tag. I want to have one common event-handler for onclick-event that could be generated in both of "<input>" tags. And then my handler will do different things depending on which tag the event was generated for.

    How can I figure out in my event-handler which tag the event was generated for?
     
    blue8sky, Feb 20, 2008 IP
  2. 2WDH.com

    2WDH.com Active Member

    Messages:
    143
    Likes Received:
    3
    Best Answers:
    5
    Trophy Points:
    68
    #2
    Hi Blue8sky.

    The following example should help you:
    <script language="Javascript" type="text/javascript">
    function [B]some_func()[/B]
    {
    	alert([B]event.srcElement[/B].name);
    }
    </script>
    
    <input type="text" name="name" onclick="[B]some_func();[/B]">
    
    <input type="text" name="phone" onclick="[B]some_func();[/B]">
    Code (markup):
    Is that what you need?
     
    2WDH.com, Feb 20, 2008 IP
  3. greboguru

    greboguru Member

    Messages:
    78
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #3
    Hi,

    I believe that the use of event.srcElement is an IE specific

     
    greboguru, Feb 21, 2008 IP
  4. blue8sky

    blue8sky Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    To: 2WDH.com
    _________

    Thanks. I needed exactly that.

    To: greboguru
    __________

    Thanks. I will try.
     
    blue8sky, Feb 23, 2008 IP