开发者

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜