admin管理员组文章数量:1374952
I have this form for processing..
<form action="driver.php" method="GET">
<input type="text" placeholder="Search" id="search" name="n">
<button type="submit">Submit</button>
</form>
by default the url is .php?n=typedname
so i did modifications in .htaccess and convert it to for SEO friendly urls modrewrite issue - 404 error thanks to anubhava
everything is well, but the problem now es when I type and click the submit button, it will go to .php?n=typedname
so how can I make it to go this url instead after clicking submit?
I think javascript can do this, so i tagged it, hope im not wrong.
thanks.
I have this form for processing..
<form action="driver.php" method="GET">
<input type="text" placeholder="Search" id="search" name="n">
<button type="submit">Submit</button>
</form>
by default the url is http://sites./driver.php?n=typedname
so i did modifications in .htaccess and convert it to http://sites./driver/typedname
for SEO friendly urls modrewrite issue - 404 error thanks to anubhava
everything is well, but the problem now es when I type and click the submit button, it will go to http://sites./driver.php?n=typedname
so how can I make it to go this url http://sites./driver/typedname
instead after clicking submit?
I think javascript can do this, so i tagged it, hope im not wrong.
thanks.
Share Improve this question edited May 23, 2017 at 12:32 CommunityBot 11 silver badge asked Dec 10, 2014 at 20:11 OverflowOverflow 872 silver badges7 bronze badges 4- 1 I am confused with what you are trying to do exactly? You're trying to go this new page after submit? Change your action URL? – cport1 Commented Dec 10, 2014 at 20:14
- so now whether you type it sites./driver/typedname or sites./driver.php?n=typedname it works ? – Yehia Awad Commented Dec 10, 2014 at 20:15
- No, this is nothing that javascript should do. Instead, make your webserver transparently redirect clients to the url with the slash. – Bergi Commented Dec 10, 2014 at 20:15
- cport I don't mean exactly to go to that url, I have just used it as an example.. it all depends what the user inputs. so whatever the user inputs and he/she clicks submit, I want it to go sites./driver/userinput – Overflow Commented Dec 10, 2014 at 20:20
2 Answers
Reset to default 5You will have to handle form submit event yourself. Something like this:
document.querySelector('form').addEventListener('submit', function(e) {
e.preventDefault();
location.href = '/driver/' + this.elements.n.value;
}, false);
jQuery
$('button[type=submit]').click(function(e){
e.preventDefault();
e.stopPropagation();
window.location = "http://sites./driver/" + $('#search').val();
return false;
});
or
$('form').submit(function(e) { // you really need to class/ID your form
// all that code
});
Now this is quick and dirty to give you the idea. You'd of course want to sanitize your input (good idea to do that on the front-end as well as the back-end).
本文标签: javascriptHow to change form url parameter on submitStack Overflow
版权声明:本文标题:javascript - How to change form url parameter on submit? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743923367a2562505.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论