I want the onclick event of a link <a href='#' onclick='function()'>
to activate when the enter button is pressed. This is supposed to work, but I don't seem to get it working. Trigger a button click with JavaScript on the Enter key in a text box . And this also didn't work for a button.
The reason for this is probably because I run and load most of my interface in with ajax because of loading issues, certain calculations take quite some time, so I figured I should use ajax to show my page elements so I can update real time instead of making the user wait 5 to 10 seconds for the server. This however seems to make the code below not working.
My code
//This comes from a different php file which is read out on the server with
//readfile() in php after an ajax call. In other words it echoes the
//contents of this file on the page including this link.
echo "<a href='#' onclick='dosomething()' ID='Enter'>Click me</a>";
//js
$("#Enter").keyup(function(event){
if(event.keyCode == 13){
$("#Enter").click();
}
});
function dosomething(){
//activate some code depends on the link.
}
So how do I get this working. Activating the onclick on enter pressed on a link imported via ajax? Is this even possible?