admin管理员组文章数量:1296391
I have this search bar:
<div id="tfheader">
<form id="tfnewsearch" method="get" action="">
<input type="text" class="tftextinput" name="q" size="21" maxlength="120"><input type="submit" value="search" class="tfbutton">
</form>
<div class="tfclear"></div>
</div>
It worked great but when I search "keyword", it will redirect to /?q=keyword.
How to redirect to ? Thank you very much !
I have this search bar:
<div id="tfheader">
<form id="tfnewsearch" method="get" action="http://mywebsite.">
<input type="text" class="tftextinput" name="q" size="21" maxlength="120"><input type="submit" value="search" class="tfbutton">
</form>
<div class="tfclear"></div>
</div>
It worked great but when I search "keyword", it will redirect to http://mywebsite./?q=keyword.
How to redirect to http://mywebsite./keyword ? Thank you very much !
Share edited Dec 20, 2014 at 13:55 baao 73.3k18 gold badges150 silver badges207 bronze badges asked Dec 20, 2014 at 12:49 BanBan 1311 gold badge2 silver badges9 bronze badges 2- possible duplicate of .htaccess rewrite query string as path – Terry Commented Dec 20, 2014 at 12:53
- You need to hook into form submit event: stackoverflow./questions/27409950/… After you have done that, you also need to make sure your server can understand this request. – dfsq Commented Dec 20, 2014 at 13:02
1 Answer
Reset to default 5You can do it with javascript
<script>
var a = document.getElementById('tfnewsearch');
a.addEventListener('submit',function(e) {
e.preventDefault();
var b = document.getElementById('tftextinput').value;
window.location.href = 'http://mywebsite./'+b;
});
</script>
and give your input field an ID called tftextinput.
<input type="text" class="tftextinput" id="tftextinput" name="q" size="21" maxlength="120">
I don't really understand why you would like to do this, as it is way more difficult to handle this request server side as it would be to simply handle the $_GET data you will receive when doing a standard form transmission.
EDIT:
Here is the full code:
<div id="tfheader">
<form id="tfnewsearch" method="get" action="http://www.mywebsite.">
<input type="text" class="tftextinput" id="tftextinput" name="q" size="21" maxlength="120"><input type="submit" value="search" class="tfbutton">
</form>
<div class="tfclear"></div>
</div>
<script>
var a = document.getElementById('tfnewsearch');
a.addEventListener('submit',function(e) {
e.preventDefault();
var b = document.getElementById('tftextinput').value;
window.location.href = 'http://mywebsite./'+b;
});
</script>
本文标签: javascriptHTML How to create search barStack Overflow
版权声明:本文标题:javascript - HTML: How to create search bar? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741628841a2389239.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论