user2680614
user2680614

Reputation:

How to send a value from a search box to a URL?

I have a search box and I have no clue how to append the string that the user searches to url after a user clicks search.

How would this work?

I have a reference code but I want to know how to append the value that a user searches:

onclick="location.href = $(this).attr('href')+'?q1=Asustablet&x=70&y=14=siys';return false" 

Here is my jsFiddle

Upvotes: 1

Views: 76

Answers (2)

itotallyrock
itotallyrock

Reputation: 21

May I suggest using PHP as it will be much easier, Add this inside PHP tags and set the variable for $user_search_input

header("Location: ".$_SERVER['REQUEST_URI']."?search=".$user_search_input);

I'm sorry if you needed a Javascript version but if not I highly suggest PHP for it has a lot of functionality being very powerful and has a lot of potential.

Upvotes: 0

Alessandro Minoccheri
Alessandro Minoccheri

Reputation: 35973

yu can't use jquery inline. you can use its events like this:

$('#search-button-4').click(function(){
    window.location.href = $(this).attr('href')+'?q1=Asustablet&x=70&y=14=siys'; 
});

DEMO

Upvotes: 3

Related Questions