www.webdeveloper.com
Results 1 to 5 of 5

Thread: onclick is not executing with keyboard enter key.

  1. #1
    Join Date
    Mar 2012
    Location
    California
    Posts
    3

    onclick is not executing with keyboard enter key.

    When I add a tabindex=0 into the below code, I can gain keyboard focus, but then when I hit the enter key, the onclick does not execute. Is there anyway to get it to execute without having to change my image to a button?

    if (role.can("deleteFilters"))
    {
    w.print("<span role=\"toolbar\" aria-label=\"Remove Filter\" class=\"employeeName\" title=\"Remove filter\" style=\"text-align: right;\" onclick=\"javascript:removeFilter('"+filterID+"');\">");
    w.print("<img src=\"icon-link-delete-dark.gif\" alt=\"delete icon\" width=\"13\" height=\"13\"/></span>&nbsp;");
    }

  2. #2
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by Newbie_Karie View Post
    When I add a tabindex=0 into the below code, I can gain keyboard focus, but then when I hit the enter key, the onclick does not execute. Is there anyway to get it to execute without having to change my image to a button?
    Any reason <span> can't be <a> ?

  3. #3
    Join Date
    Mar 2012
    Location
    California
    Posts
    3
    I swapped out the <span for <a ..
    same issue, does not execute with the keyboard enter key.

  4. #4
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by Newbie_Karie View Post
    I swapped out the <span for <a ..
    same issue, does not execute with the keyboard enter key.
    Code:
    <script type='text/javascript'>
    
    var filterID = 'Works';
    
    document.write("<a href='#' role=\"toolbar\" aria-label=\"Remove Filter\" class=\"employeeName\" title=\"Remove filter\" style=\"text-align: right;\" onclick=\"removeFilter('"+filterID+"');return false;\">LINK");
    document.write("<img src=\"icon-link-delete-dark.gif\" alt=\"delete icon\" width=\"13\" height=\"13\"/></a>&nbsp;");
    
    
    function removeFilter( id )
    {
      alert( id );   
    }
    
    </script>

  5. #5
    Join Date
    Mar 2012
    Location
    California
    Posts
    3
    Thank you very much. Using your code I was able to get the functionality to work. What I had originally attempted to use did not include the href='#' you cited above. Cheers!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles