Reputation: 49
i am using a form and i have to use button and type is submit when i pressed enter key the form submit, so i want to remove the functionality of enter key.
<input name="bb" id="bb" type="text" onKeyUp="Javascript: if(event.keycode==13) dont_submit(key); else show_error(this.value, event.keycode, this.id)";>
<script type="text/javascript">
function dont_submit(key)
{
if(key)
{
return false;
}
}
</script>
i also try this but not worked
<script type="text/javascript">
function dont_submit(key)
{
if(key == 13)
{
return false;
}
}
</script>
Upvotes: 1
Views: 5259
Reputation: 3662
$('#button').keypress(function () {
if(e.which == 13) {
return false;
}
});
Upvotes: 0
Reputation: 66389
Simply don't put a submit button but rather plain button with JS to submit the form:
<input type="button" class="SubmitButton" value="Submit" onclick="this.form.submit();" />
If you're concerned about visitors without JavaScript, use such code:
<noscript>
<style type="text/css">
.SubmitButton { display: none; }
</style>
<input type="submit" value="Submit" />
</noscript>
Upvotes: 1
Reputation: 3740
$(document).keypress(function (e) {
if(e.which == 13)
return false;
});
Upvotes: 1