pee2pee pee2pee - 1 month ago 18
reST (reStructuredText) Question

jQuery - Submit Form to RESTful URL

My mind has gone 100% blank on this so need some guidance please.

<form action="/" id="searchForm">
<input type="text" name="s" placeholder="Search...">
<input type="submit" value="Search">
</form>


I need that form so the page redirects to a URL such as

http://example.com/rest/ful/url/{value of search}/
e.g.
http://example.com/rest/ful/url/jQuery/
if I searched for
jQuery


Do I even need jQuery for this?

Answer

Solution with jquery:

$('#searchForm').on('submit', function(event){
    $('[name=s]').prop('disabled', true)
    $(this).attr('action', 'http://example.com/rest/ful/url/' +     $('[name=s]').val());
});

https://jsfiddle.net/3y4efht0/1/

Comments