1

Possible Duplicate:
pass inputbox value as a querystring to URL

<input name="KeywordBox" class="BasicSearchInputBox" type="text" value="Keywords.."/>
<a class="searchButton" href="/search/pages/Careers.aspx?v=relevance&s=Careers&k=" type="submit">
    <span>Search</span>
</a> 

How do you get the keywords typed in by users and pass it to the page or append to the URL onclick of the 'Search' link?

Like this http://mycompany.com/search/pages/Careers.aspx?v=relevance&s=Careers&k=engineer

Using jquery?

Community
  • 1
  • 1
AJSwift
  • 709
  • 4
  • 12
  • 26

2 Answers2

3

The simplest method is to place your inputs into a form and submit them to your page using the GET method.

If you'd prefer to use jQuery, you can do:

$(function() {
    $(".searchButton").click(function() {
        var keywords = $("#KeywordBox").val();
        window.location.assign("/search/pages/Careers.aspx?v=relevance&s=Careers&k=" + keywords);
    });
});

Just make sure you sanitise your input values properly otherwise you're leaving yourself open to injection attacks.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
1

You can use the .serialize() method

parapura rajkumar
  • 24,045
  • 1
  • 55
  • 85