Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simulate anchor click?

Status
Not open for further replies.

Naoise

Programmer
Joined
Dec 23, 2004
Messages
318
Location
IE
I have a text box and a link in a form. I need the link to be clicked when the return key is hit in the text box. It is quite easy to catch the return key but I don't think I can simulate a click event for the anchor.

I know you can do it for an input button type but I need this to be an anchor tag. Any suggestions?
 
I'm having some trouble understanding yur problem. Perhaps you can explain it better.
I think you may want to try something like
Code:
<a href="" onClick="document.myForm.submit()">Submit</a>

I don't know the answer but my good friend Google does.
 
I don't want a form to be submitted I just want the click event of the anchor text to be simulated.

The larger picture is that I have an asp.net page which detects if the link has been clicked and fires some logic. I have done this before with a button as it has a .click property that can be set to true, is there a workaround for a link?
 
I doubt very much whether you will find a cross-browser way of simulating a click.

However, you could simply go to the URL specified by the anchor, e.g.:

Code:
location = yourAnchorObj.href;

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top