views:

572

answers:

1

I would like to submit a form, specifically an input field to a URL based on the input field's value using GET.

Example: Input field value is "test". Submit GETs www.myurl.com/Products/Search/test

Example: Input field value is empty. Submit GETs www.myurl.com/Products/Search/

Example: Input field value is "123". Submit GETs www.myurl.com/Products/Search/123

How could I do this using jQuery? Probably intercepting the submit..?? Thank you for your help!

+2  A: 
$('form').submit(function() {
    this.action += $('#myInput').val();
    return true;
});
Darin Dimitrov
This works great, except that it appends the input still also as ?input=value (e.g. www.myurl.com/Products/Search/test?search=test). How can I get rid of the query string part?
Alex
try removing the #myInput after getting value. $("#myInput").remove()
TheVillageIdiot
@TheVillageIdiot: That kinda worked, but its clearly visible that I'm removing the input (visibly disappears before submit) which would confuse the hell out of users :( --- very cool workaround attempt though. The idea made me smile. Any idea how to do this without making the input disappear?
Alex
try $('#myInput').text() instead.
Mike