Why not srabotaet window.location.href?

here is the form

<form id="w0" method="get" action="find">
 <input type="text" placeholder="Search" value name="query">
 <div class="form-group">
 <button onclick="window.location.href=this.form.action+'-'+this.form.query.value" type="submit">
 <i class="fa fa-search"></i>
</button>
</div>
 </form>


get clicking on that button this address
http://film.lc/%найти?query=запрос

if I do so

<form id="w0" method="get" action="find">
 <input type="text" placeholder="Search" value name="query">
 <div class="form-group">
 <button onclick="alert(window.location.href=this.form.action+'-'+this.form.query.value)" type="submit">
 <i class="fa fa-search"></i>
</button>
</div>
 </form>


Then after a while, if not click on window alert window.location.href'll work and I'll get the address http://film.lc/найти-запрос.
Why the first form does not work tell me and how to deal with it
July 9th 19 at 10:35
1 answer
July 9th 19 at 10:37
Because you need to deactivate the default events...
//Or
event.preventDefaults();
//Or
return false;

Find more questions by tags JavaScript