'Stop input type number from submitting the form on enter button

So this is an unusual situation (for me) and let's see if I can survive it without pulling my hair out. I am working on a grails application and had to implement an extra field in a form that does something rather separately from the form submission. The problem is that the only place that field can go is inside the form. That said I have the field doing exactly what it has to, the problem is that I cannot prevent the field (a number field btw) from firing a form submission which in turn does something more than I can understand because it is a grails form sending filters to a controller which I am not in a position to understand.

this is the jquery I've used to do what I need to do. #page-number is the number field I want to prevent from submitting the form. Any help appreciated. Oh and also, there's no attempt here to do that since I've tried many with event.keycode, onkeyup, keypress, with preventDefault() and so on and so on, the form always submits. Again, this number field must be within the form it is right, so taking it out of the form is not an option that fits this scenario.

$("#go-to").click(function(){
    let url = new URL(location.href);
    let url_params = url.searchParams;
    url_params.set("offset", (parseInt($("#page-number").val()) * 10) -1);
    url.search = url_params.toString();
    window.location = (url);
});


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source