Alex
Alex

Reputation: 77329

Use jQuery to dynamically alter Form GET target on Submit

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!

Upvotes: 2

Views: 1394

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038730

$('form').submit(function() {
    this.action += $('#myInput').val();
    return true;
});

Upvotes: 2

Related Questions