I have a link that looks like this.
<a id="link" href="../customer_record/?id=1&customer_id=2"></a>
I also have an input box as the following.
<input type="text" id="search">
I am trying to get jQuery to add a parameter to the link as the user types into the input box.
// add search to link
$('#search').on('keyup', function(){
var href = $('#link').attr("href");
var data = $(this).val();
$('#link').attr('href', href + '&search-string=' + data);
});
I don’t think I am far away but I just can’t get it to work.
Any help would be gratefully appreciated.
2
Answers
u almost there
You can set the URL query string with URLSearchParams: set() method of URL API. See the following example.