Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Programmatically click a LinkButton

    Hi I have been trying for a while to get a linkbutton to click when the enter key is pressed.

    Currently I have:
    Code:
    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

  • #2
    Regular Coder
    Join Date
    May 2007
    Posts
    118
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Palazio,

    Try this code...

    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');">
    Forum for webmasters and developers
    http://www.htmlfrenzy.com
    Are you an IT expert? Join our Reward system
    www.htmlfrenzy.com/reward-system.php

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •