Reputation: 457
I want to redirect people like this: example.com/search/[search+text]
html source code:
<form name="menu_search" method="get" onsubmit="window.location.href = 'http://www.col3negmovie.com/search/'+this.q.value+''; return false;" >
<input name="q" id="videoSearch" />
</form>
this is the anchor link :
<a href="./#" onclick="document.menu_search.submit(); window.location.href='http://www.col3negmovie.com/search/'+this.q.value+''; return false;">Search</a>
onclick doesn't work, how could i fix this?
onclick="document.menu_search.submit();
window.location.href='http://www.col3negmovie.com/search/'+this.q.value+'';
return false;"
Upvotes: 0
Views: 1337
Reputation: 7060
Your form:
<form name="menu_search" method="get" onsubmit="window.location.href = 'http://www.col3negmovie.com/search/'+document.getElementsByName('q')[0].value+''; return false;" >
<input name="q" id="videoSearch" />
</form>
Anchor tag:
<a href="./#" onclick="document.getElementsByName('menu_search')[0].submit(); return false;">Search</a>
Or without the <form>
tag (which makes it less confusing):
<input name="q" id="videoSearch" />
<a href="./#" onclick="window.location.href = 'http://www.col3negmovie.com/search/' + document.getElementById('videoSearch').value;">Search</a>
To do the same when 'Enter' is pressed:
document.getElementById("videoSearch").onkeyup = function() {
if (this.event.keyCode == 13 || this.event.which == 13)
//Enter was pressed, handle it here
window.location.href = 'http://www.col3negmovie.com/search/' + document.getElementById('videoSearch').value;
}
}
Hope that helped.
Upvotes: 2