Setting a href property in a anchor tag with Javascript
-
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:
-
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:
Hi
<a href="javascript:test()">
Click Me...
</a>
<script>
function test()
{
alert("Thanks.");
}
</script>Mohammad Khansari
-
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:
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 -
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 JavascriptThanks 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: