开发者

Submit form with no action atribute pressing enter key

开发者 https://www.devze.com 2023-03-27 00:24 出处:网络
<form action=\"\" name=\"searchForm\" id=\"searchForm\" method=\"post\"> How can I make it submit using Javascript when user press enter?
<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

精彩评论

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