javascriptie-mobile

Convert enter to tab in windows mobile


Have the following piece of javascript over on http://jsfiddle.net/mhenrixon/zPLgS/16/ and its working fine in regular browsers but I can't make it work in IE Mobile for Windows CE 6.0 where it needs to work. Anyone knows how to fix that?

function tab(field, event) {
    if (event.which == 13 /* IE9/Firefox/Chrome/Opera/Safari */ || event.keyCode == 13 /* IE8 and earlier */ ) {
        for (i = 0; i < field.form.elements.length; i++) {
            if (field.form.elements[i].tabIndex == field.tabIndex + 1) {
                field.form.elements[i].focus();
                if (field.form.elements[i].type == "text") {
                    field.form.elements[i].select();
                    break;
                }
            }
        }
        return false;
    }
    return true;
}​

Solution

  • Thanks guys the problem was not getting the key and it was not changing propagation or anything like that it was actually quite easy.

    Full solution

    function tab(field, event) {
      if (event.which == 13 /* IE9/Firefox/Chrome/Opera/Safari */ || event.keyCode == 13  /* IE8 and earlier */) {
        nextElement(field);
        return false;
      }
      return true;
    }
    
    function nextElement(field) {
      for (var i = 0; i < field.form.elements.length; i++) {
        if (field.form.elements[i].tabIndex == field.tabIndex + 1) {
          field.form.elements[i].focus();
          if (field.form.elements[i].type == "text") {
            field.form.elements[i].select();
            break;
          }
        }
      }
    }