Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
131
rated 0 times [  133] [ 2]  / answers: 1 / hits: 34121  / 9 Years ago, mon, december 7, 2015, 12:00:00

I have a form like this:



<form action=http://localhost/test>
<input type=text name=keywords>
<input type=submit value=Search>
</form>


If I type a value, let's say: 'hello' in the text input field and submit the form, the URL looks like: http://localhost/test/?keywords=hello.



I want the value to get appended to the action path. So basically, after the form submission the URL should look like:



http://localhost/test/hello

More From » html

 Answers
16

You can use onsubmit attribute and set the action inside a function for example:


<form id="your_form" onsubmit="yourFunction()">
<input type="text" name="keywords">
<input type="submit" value="Search">
</form>

function yourFunction(){
var action_src = "http://localhost/test/" + document.getElementsByName("keywords")[0].value;
var your_form = document.getElementById('your_form');
your_form.action = action_src ;
}


[#64148] Thursday, December 3, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jennie

Total Points: 593
Total Questions: 102
Total Answers: 106

Location: Federated States of Micronesia
Member since Fri, Sep 16, 2022
2 Years ago
jennie questions
;