-1

The enter key in this script does not click the 'new' button.

Am I missing something here?

The button:

<script>
<a class="btn btn-primary"  id="new" href="@Url.Action("New", "New")">New</a>
</script>

The script:

<script> 
        $(document).keypress(function (e) {
            if (e.which == 13) {
                $("#new).click();
            }
        });
</script>

1 Answers1

0
$(document).bind('keypress', function (e) {
    if (e.keyCode == 13) {
        $('#new').trigger('click');    
    }
  return false;    
});

Missing " and use 'trigger' function.

RGS
  • 5,131
  • 6
  • 37
  • 65