pass inputbox value as a querystring to URL

一个人想着一个人 提交于 2019-12-18 09:22:15

问题


I have an inputbox and a link for SEARCH styled to look like a Search button. When a user types in a keyword in the inputbox, I want to grab that keyword, pass it, and append it as a search query string to the search URL

/search/pages/physicians.aspx?v=relevance&s=Physicians&k=

So if Cardiologist is the keyword, it would be like:

http://ABChospital.org/search/pages/physicians.aspx?v=relevance&s=Physicians&k=Cardiologist

How can I achieve this in jquery?

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

回答1:


Try this:

$('.searchButton').click(function() {
    location.href = this.href + $('.BasicSearchInputBox').val();
    return false;
});


来源:https://stackoverflow.com/questions/8387494/pass-inputbox-value-as-a-querystring-to-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!