...

View Full Version : Programmatically click a LinkButton



palazio
05-10-2007, 09:50 PM
Hi I have been trying for a while to get a linkbutton to click when the enter key is pressed.

Currently I have:


function KeyDownHandler(event, btn)
{
if (event.keyCode == 13)
{
event.returnValue = false;
event.cancel = true;

if (btn.click) //IE
{
btn.click();
}
else //Firefox (hopefully)
{
var e = document.createEvent("MouseEvents");

e.initEvent("click", true, true);
btn.dispatchEvent(e);
}
}
}

Where btn is the object which I want to click

btn.click() doesn't work for firefox, so I found somewhere that the above is how you do the equivalent for firefox but it doesn't work not even a javscript error.

Any Suggestions??!!?

Thanks

smalldog
05-10-2007, 10:09 PM
Hi Palazio,

Try this code...



<script>
function KeyDownHandler(event, id)
{
if (event.keyCode == 13)
{
event.returnValue = false;
event.cancel = true;
document.getElementById(id).click()
}
}
</script>
<input type="text" onkeydown="KeyDownHandler(event,'testb');">
<input type="button" id="testb" onclick="alert('a');">

glenngv
05-12-2007, 09:06 PM
http://www.codingforums.com/showthread.php?p=565402#post565402



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum