0

I am trying the following code to fire click event on a textbox while clicking on a button as the focus() function is not working in IE8

function simulateClick(elm) {
  var evt = document.createEvent("MouseEvents");
  evt.initMouseEvent("click", true, true, window,
      0, 0, 0, 0, 0, false, false, false, false, 0, null);
  var canceled = !elm.dispatchEvent(evt);
  if(canceled) {
     // A handler called preventDefault
     // uh-oh, did some XSS hack your site?
  } else {
     // None of the handlers called preventDefault
     // do stuff
  }
}

This code works fine if the element is of type checkbox but not textbox, is there anything I might need to add?

Ryan
  • 265
  • 1
  • 6
  • 17
  • Can you show the code for focus() you claim does not work in IE8? createEvent is as far as I know not supported in IE. have a read here: http://www.howtocreate.co.uk/tutorials/javascript/domevents – mplungjan Dec 16 '10 at 10:10
  • textbox support focus just fine: http://jsfiddle.net/J9qQj/ working fine in IE, Chrome and Firefox so the problem is something else in your code feel free to post it and we'll take a look. – Shadow The GPT Wizard Dec 16 '10 at 10:22

1 Answers1

0

This is the code for focus

function ResponseEnd(sender, args) {
        if (args.get_eventArgument().indexOf("Filter") != -1) {
            var grid = document.getElementById("<%= radGridEnquiries.ClientID %>");
            var label =  $(grid).children("table").children("tbody").children(".rgRow").children("td:has(span)").children("span")[0];
            if (label != null) {
                label.focus();
            }
            else {
                var noRecTemp = $(grid).children("table").children("tbody").children("tr.rgNoRecords").children("td:has(div)").children("div");
                noRecTemp.focus();
            }
        }

        if (postInProgress)
            postInProgress = false;
    }

The real scenario is I have some textboxes set as filters in a Telerik RadGrid and having no filter icons but when the user posts a filter and the request is finished in IE8 the filter textbox is still with focus preventing the user to input new filters unless clicks on the textbox manually again

P.S. Sorry if this post is seen as answer but couldn't update this question with proper indented code. Thanks

Ryan
  • 265
  • 1
  • 6
  • 17