I have to prevent empty search submit on search forms. Forms does not have submit buttons, so I have to prevent the enter.
The html code:
Form 1
<form method="get" class="search-form" id="searchform" action="http://example.com" >
<input class="text" name="s" id="s" type="text" />
</form>
Form 2
<form action="http://example.com" class="search-form" method="get">
<input type="text" name="s" class="text">
</form>
The Javascript code
// Im sure this funcions returns the 2 different forms,
var searchForms = getElementsByClass('search-form');
for(i in searchForms)
{
if (searchForms[i].addEventListener)
{
searchForms[i].addEventListener("submit", function(e)
{
preventSubmit(e); // no problem here
console.log(i) // ALWAYS LOGS 1
});
} //I also implemented the ie code, but not necessary here, is the same as above for addEventListener
}
Every time I submit any form, writes 1 in the console, any idea?