lamrin
lamrin

Reputation: 41

jquery - click event

In the lightbox i render form containing textbox and buttons (next and prev).

Problem is, after i edit content in textbox and click "Enter button" it should fire click event on "next" button so that it takes to next form in lightbox

I used following code, but it is refreshing entire page instead of focusing "next" button alone.

And it gives error: ActionController::MethodNotAllowed Only get requests are allowed

$("input").bind('keyup', function(event) {
    if(event.keyCode == 13) {
       $("#nextbtn").click();
    }
});

please correct if any thing wrong with the syntax

Upvotes: 1

Views: 198

Answers (2)

Jacob Relkin
Jacob Relkin

Reputation: 163228

You need to return false and call preventDefault on the event object in order to prevent submission of the form.

$( 'input' ).bind( 'keyup', function( e ) { 
    if( e.keyCode == 13 ) { 
       $( '#nextbtn' ).click(); 
    }
    e.preventDefault();
    return false;

} );

Also, change your method attribute to GET, the error is stating that you cannot submit POST requests.

Upvotes: 3

niggles
niggles

Reputation: 1034

You may also need to invoke the page as an Iframe from the Lightbox so it doesn't close automatically once the form is submitted.

Most lightbox plugins for Jquery give a parameter to launch it as an iframe.

Upvotes: 0

Related Questions