JavaScript jQuery UI Dialog Changes URL on Enter KeyPress

You can prevent the default action of an event with event.preventDefault(). I am not 100% sure how the form looks like in jQuery-ui and if preventing the default of the keypress works. As an alternative you can prevent the default action of the submit event which, as you would probably expect, prevents the form from being submitted (as per Gokul's answer). See mdn for more information on event.preventDefault().

$('#answer').keypress(function(e) {
    if (e.keyCode == $.ui.keyCode.ENTER) {
          e.preventDefault();
    }
});

-- or --

$('whatevertheuiformis').on( 'submit', function(e) {
    if (e.keyCode == $.ui.keyCode.ENTER) {
          e.preventDefault();
    }
});
Answer:1

As yours...

<form>
<!-- <form onsubmit="return false"> is an optional -->
<fieldset>
    <label for="answer">
        <strong>Your Answer : </strong>
    </label>
    <input type="text" name="answer" id="answer" 
           class="text ui-widget-content ui-corner-all" />
</fieldset>
</form>

//jQuery Version
$('form').submit(function(){
    return false;
});
// javascript
document.getElementById('my-form').onsubmit = function() {
    return false;
}
$('#answer').keypress(function(e) {
    if (e.keyCode == $.ui.keyCode.ENTER) {
        e.preventDefault();
        //alert("enter pressed on answer input");
        submit_with_ajax(answer);
    }
});

So Here the Form will not submit at all.. so that you can perform your AJAX submission or REQUEST....

Hope it helps...

Answer:2

In ECMAScript 6, I have two way to define a dictionary: Traditional method (with dictionary = Object.create(null)): set property: dictionary.key = value or dictionary[key] = value get property: ...

In ECMAScript 6, I have two way to define a dictionary: Traditional method (with dictionary = Object.create(null)): set property: dictionary.key = value or dictionary[key] = value get property: ...

I like the off canvas feature that bootstrap 3 has: http://getbootstrap.com/examples/offcanvas/. However, for one of my projects i'd like it to overlap the content rather than move the content to the ...

I like the off canvas feature that bootstrap 3 has: http://getbootstrap.com/examples/offcanvas/. However, for one of my projects i'd like it to overlap the content rather than move the content to the ...

I would like to be able to detect if an object I'm looking at is an instance of _.template, the same way I can check for Backbone Models/Collections/Views. for example: var newView = new Backbone....

I would like to be able to detect if an object I'm looking at is an instance of _.template, the same way I can check for Backbone Models/Collections/Views. for example: var newView = new Backbone....

I'm using the Google Book Viewer API to show book previews based on metadata found on the page. This is in a system I don't control, although I can append scripts and markup. Only some pages contain ...

I'm using the Google Book Viewer API to show book previews based on metadata found on the page. This is in a system I don't control, although I can append scripts and markup. Only some pages contain ...

  1. google book viewer
  2. google book ngram viewer
  3. google labs book ngram viewer