Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Anchor onclick attribute

Anchor onclick attribute

Scheduled Pinned Locked Moved Web Development
javajavascripttoolshelpannouncement
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    salmonraju
    wrote on last edited by
    #1

    Hi, Below is the issue I am facing in Java script. I am using <TR> in that Tr i have 3 <Td> in last <td> I am using anchor tag dome thing like below <tr name =row> <td/> <td/> <td> <a type="aaa" onclick="UpdateName" > test </a> I am assigning dynamically all the attributes of anchor tag like below var cells= row.cells; var link = cells(2).all.tags("A")(0); link.file= "123"; link.href = "javascript:VoidReturn("nothing to return"); link.onclik=function() { updateName(name);} function Update(name) { username=name; } This is working fine if i am using link onclick attribute as above ...function() { updateName(name);} but if i am just giving it as string, it is not invoking, like below. link.onclick=updateName('abc'); Please let me know how i can set onclick of anchor attribute without function object. Thanks, Salmon

    D 1 Reply Last reply
    0
    • S salmonraju

      Hi, Below is the issue I am facing in Java script. I am using <TR> in that Tr i have 3 <Td> in last <td> I am using anchor tag dome thing like below <tr name =row> <td/> <td/> <td> <a type="aaa" onclick="UpdateName" > test </a> I am assigning dynamically all the attributes of anchor tag like below var cells= row.cells; var link = cells(2).all.tags("A")(0); link.file= "123"; link.href = "javascript:VoidReturn("nothing to return"); link.onclik=function() { updateName(name);} function Update(name) { username=name; } This is working fine if i am using link onclick attribute as above ...function() { updateName(name);} but if i am just giving it as string, it is not invoking, like below. link.onclick=updateName('abc'); Please let me know how i can set onclick of anchor attribute without function object. Thanks, Salmon

      D Offline
      D Offline
      daveyerwin
      wrote on last edited by
      #2

      salmonraju wrote:

      link.onclik=function() { updateName(name);}

      OK the above assigns the Function to the onclick . Now this next part assigns the results of updateName('abc') (which is a function call) to the onclick , you don't want that.

      salmonraju wrote:

      link.onclick=updateName('abc');

      I can't do anything with the code you presented so I will give this simple example ...

      <table>
      <tr name="row">
      <td>
      <a name="a1">a1</a>
      <td/>
      <td>
      <a name="a2">a2</a>
      <td/>
      </tr>
      </table>
      <script>
      as = document.getElementsByTagName("A")

      as[0].href = '#';
      as[0].innerHTML = "HIYAS";
      as[0].onclick = Update;
      as[0].aname = "Davey"

      as[1].href = '#';
      as[1].innerHTML = "Whassup";
      as[1].onclick = Update;
      as[1].aname = "JONES"

      function Update()
      {
      alert(this.aname);
      }
      </script>

      Try that out and see if it works for you.

      L 1 Reply Last reply
      0
      • D daveyerwin

        salmonraju wrote:

        link.onclik=function() { updateName(name);}

        OK the above assigns the Function to the onclick . Now this next part assigns the results of updateName('abc') (which is a function call) to the onclick , you don't want that.

        salmonraju wrote:

        link.onclick=updateName('abc');

        I can't do anything with the code you presented so I will give this simple example ...

        <table>
        <tr name="row">
        <td>
        <a name="a1">a1</a>
        <td/>
        <td>
        <a name="a2">a2</a>
        <td/>
        </tr>
        </table>
        <script>
        as = document.getElementsByTagName("A")

        as[0].href = '#';
        as[0].innerHTML = "HIYAS";
        as[0].onclick = Update;
        as[0].aname = "Davey"

        as[1].href = '#';
        as[1].innerHTML = "Whassup";
        as[1].onclick = Update;
        as[1].aname = "JONES"

        function Update()
        {
        alert(this.aname);
        }
        </script>

        Try that out and see if it works for you.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Great Answer :omg:

        Jinal Desai

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups