What can be overriding the prevent default ? Pressing enter to click target submits the form but doesn't click (javascript/Jquery) -
i have simple code...
document.addeventlistener('keydown', function (e) { if (e.keycode == 13 || e.keycode == 32) { e.preventdefault(); $(e.target).trigger("click"); } });
this working fine keycode 32 (space), not keycode 13 (enter) submits form. tried adding prevent default after reading answers similar questions, doesnt solve issue. form submitted anyways after pressing enter.i looking after solution can written in script tag; since not want disturb form tags. also, script(without prevent default) working fine till days ago.
su-j, if using input
field submit, can add attribute somewhere this: <input type="submit" onsubmit="return false;"/>
. or can add <form>
tag <form type="post" onsubmit="return false;"/>
edit: i'd try keypress
instead. keypress raised character keys (unlike keydown , keyup, raised noncharacter keys) while key pressed. "higher-level" event either keydown or keyup, , such, different data available in eventargs.
see more answers here
Comments
Post a Comment