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. ASP.NET
  4. Setting a href property in a anchor tag with Javascript

Setting a href property in a anchor tag with Javascript

Scheduled Pinned Locked Moved ASP.NET
tutorialjavascripthelp
4 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.
  • T Offline
    T Offline
    Tina P
    wrote on last edited by
    #1

    Hello All, I need to be able to set an href property of an anchor tag to a javascript which will basically mimick a mouse click event. Can someone show me an example of how to go about doing that. I have barely used Javascript and not too familiar with it. Any help would be higly appreciated. Thanks ~tina :confused:

    M A 2 Replies Last reply
    0
    • T Tina P

      Hello All, I need to be able to set an href property of an anchor tag to a javascript which will basically mimick a mouse click event. Can someone show me an example of how to go about doing that. I have barely used Javascript and not too familiar with it. Any help would be higly appreciated. Thanks ~tina :confused:

      M Offline
      M Offline
      m khansari
      wrote on last edited by
      #2

      Hi

      <a href="javascript:test()">
      Click Me...
      </a>
      <script>
      function test()
      {
      alert("Thanks.");
      }
      </script>

      Mohammad Khansari

      1 Reply Last reply
      0
      • T Tina P

        Hello All, I need to be able to set an href property of an anchor tag to a javascript which will basically mimick a mouse click event. Can someone show me an example of how to go about doing that. I have barely used Javascript and not too familiar with it. Any help would be higly appreciated. Thanks ~tina :confused:

        A Offline
        A Offline
        Abhishek Sur
        wrote on last edited by
        #3

        function changeAnchor(){
        var anchor = document.getElementById('myanchor');
        anchor.href = 'javascript:alert("you might call any function here");';
        }

        <a href="javascript:changeAnchor();" id="myanchor" > Click me </a>

        This will change the anchor href property during first click of the anchor. ;)

        Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


        My Latest Articles-->** Simplify Code Using NDepend
        Basics of Bing Search API using .NET
        Microsoft Bing MAP using Javascript

        T 1 Reply Last reply
        0
        • A Abhishek Sur

          function changeAnchor(){
          var anchor = document.getElementById('myanchor');
          anchor.href = 'javascript:alert("you might call any function here");';
          }

          <a href="javascript:changeAnchor();" id="myanchor" > Click me </a>

          This will change the anchor href property during first click of the anchor. ;)

          Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


          My Latest Articles-->** Simplify Code Using NDepend
          Basics of Bing Search API using .NET
          Microsoft Bing MAP using Javascript

          T Offline
          T Offline
          Tina P
          wrote on last edited by
          #4

          Thanks guys! Abhishek, as I mentioned I wanted to mimicks the mouse click event (i.e the exact same thing that happens when a user uses a mouse to click on something) but instead I'm trying to do it from the tab button....so having said that how's an alert dialog box going to help. When the tab is hit and the user hits enter on the link, this event needs to fire so that the other code (which we already have that opens up another page will execute, so my problem is to make this work within these constraints, i cant just show the user an alert box! Can you elaborate on this a little bit, thanks guys! ~Tina   :omg:

          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