开发者

Submit form with no action atribute pressing enter key

<form action="" name="searchForm" id="searchForm" method="post">

How can I make it submit using Javascript when user press enter?

edit: assuming I can't edit the <html>, only using JS (jQuery if really needed)

edit2: it will also be great if myFormProcessF开发者_开发百科unction() was loaded

accept

Just capture the submit function as if the form had been submitted via the enter button normally.

document.searchForm.submit = function()
{
    myFormProcessFunction()

    return false; // prevents default action
}


Just capture the submit function as if the form had been submitted via the enter button normally.

document.searchForm.submit = function()
{
    //do something

    return false; // prevents default action
}


$('#searchForm').submit(function(e) {     
   e.preventDefault();
   return false; 
})

try that, I am sure it'll work. It uses jQuery plulgin, so make sure you have it included.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜