JS/JQ simulate Enter event

THX to the awesome Eran Hertz our programming Architect!

thing is that the trigger event needs some extra stuff to trigger the right thing:

var press = jQuery.Event("keypress");
press.altGraphKey = false;
press.altKey = false;
press.bubbles = true;
press.cancelBubble = false;
press.cancelable = true;
press.charCode = 13;
press.clipboardData = undefined;
press.ctrlKey = false;
press.currentTarget = $("#myTextBox")[0];
press.defaultPrevented = false;
press.detail = 0;
press.eventPhase = 2;
press.keyCode = 13;
press.keyIdentifier = "";
press.keyLocation = 0;
press.layerX = 0;
press.layerY = 0;
press.metaKey = false;
press.pageX = 0;
press.pageY = 0;
press.returnValue = true;
press.shiftKey = false;
press.srcElement = $("#myTextBox")[0];
press.target = $("#myTextBox")[0];
press.type = "keypress";
press.view = Window;
press.which = 13;
$("#myTextBox").trigger(press);



and for the short version:
var press = jQuery.Event("keypress");
press.bubbles = true;
press.cancelable = true;
press.charCode = 13;
press.currentTarget = $("#myTextBox")[0];
press.eventPhase = 2;
press.keyCode = 13;
press.returnValue = true;
press.srcElement = $("#myTextBox")[0];
press.target = $("#myTextBox")[0];
press.type = "keypress";
press.view = Window;
press.which = 13;

p.s. - for all of u guys that came from stackoverlow.com u can grant me great joy by marking my answers, thx!!!

Comments

  1. Excellent post. I was checking constantly this blog and I'm impressed!
    Very helpful information particularly the last part :) I
    care for such information much. I was seeking this certain information for a
    very long time. Thank you and good luck.

    Feel free to surf to my webpage - cellulit na brzuchu

    ReplyDelete
  2. Thanks for sharing, nice post! Post really provice useful information!

    An Thái Sơn chia sẻ trẻ sơ sinh nằm nôi điện có tốt không hay võng điện có tốt không và giải đáp cục điện đưa võng giá bao nhiêu cũng như mua máy đưa võng ở tphcm địa chỉ ở đâu uy tín.

    ReplyDelete
  3. daetheiblan_ko-Boston Chris Kumar software
    Link
    noifranutel

    ReplyDelete

Post a Comment

Popular posts from this blog

OverTheWire[.com] Natas Walkthrough - JUST HINT, NO SPOILERS

Asp.Net Ending Response options, Response.End() vs CompleteRequest()

SOLVED The item could not be indexed successfully because the item failed in the indexing subsystem