SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2011
    Location
    Trinidad and Tobago
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to get the value of a clicked link

    I have a list of links which all have different values but the same id (yes that was my mistake). How can I get the value of the link please see below for my link code.

    Code:
    <a href='#' id='bookmark' onclick='bookmark()' value='"+rtndata[j].venueid+"'></a>
    When the link is clicked the function bookmark is called within that function I want to get the value of the link clicked

    any help will be greatly appreciated

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,071
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Code:
    function bookmark()
    {
      this.getAttribute('value')
    }

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2011
    Location
    Trinidad and Tobago
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    Code:
    function bookmark()
    {
      this.getAttribute('value')
    }
    when i try this
    Code:
    var button = this.getAttribute('value');
    i get the error this.getAttribute is not a function what seems to be the problem?

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by skelleex View Post
    when i try this
    Code:
    var button = this.getAttribute('value');
    i get the error this.getAttribute is not a function what seems to be the problem?
    It means that this keyword is not an object that has the getAttribute method, which means that the this keyword in that particular situation quite likely refers to the window object instead.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,071
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    See the following url, I modified your HTML markup a bit, but it works.
    http://jsfiddle.net/cpradio/qLKcE/

  6. #6
    SitePoint Zealot
    Join Date
    Aug 2011
    Location
    Trinidad and Tobago
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    See the following url, I modified your HTML markup a bit, but it works.
    http://jsfiddle.net/cpradio/qLKcE/
    this works thanks alot


Bookmarks

Posting Permissions

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