javascript - prevent form submit by pressing enter key on struts-dojo autocomplete -
i trying alter enter event struts2-dojo autocomplete, inseted of submitting form should of jquery work.
i tried...
<s:form action="empaction"> <sx:autocompleter label="name" name="name" list="namelist" id="name" showdownarrow="false" /> <s:textfield name="test" label="test" id="test"/> </s:form>
and in jquery...
<script type="text/javascript"> $(function(){ $('#name').key(function(e) { if (e.keycode == 13) { e.preventdefault(); alert($(this).val()); //and jquery code json , fill test textfield. return false; } }); }); </script>
but still submits form, have used
e.preventdefault();
in many cases , got success here not working.
this code work in context
$(document).ready(function() { $(window).keydown(function(event){ if(event.keycode == 13) { if(event.currenttarget != $("yourautocompleteid")){ event.preventdefault(); mypersonalfunctioncall(); } else{$("yourautocompleteid").one("onfocus", false);} return false; } }); });
Comments
Post a Comment