0

I need to be able to create a query based off the users input of "Test" in an INPUT of Site A (SiteA.com) that will open Site B in the same window once submitted, passing along the query (SiteB.com/search.aspx?k=test).

Code on SiteA.com

var siteSearch = "SiteB.com/search.aspx";

$("#sitesubmitBtn").click(submitClick);
function submitClick() {
    var q = $(location).attr('protocol') + "//" + $(location).attr('hostname') + siteSearch;
    var k = $("#sitesearchInput").val();
    window.location.href = q + "?k=" + k;
    return false;
}
<input name="search" placeholder="Search" id="sitesearchInput" type="text">
<button id="sitesubmitBtn" type="submit"></button>

2 Answers 2

1

You are describing a simple HTML form. You don't need JavaScript/jQuery for that to happen.

<form method="GET" action="//SiteB.com/search.aspx">
    <input type="text" name="k" placeholder="Search term" />
    <button type="submit">Search</button>
</form>

Sign up to request clarification or add additional context in comments.

Comments

0

change this line

    var q = $(location).attr('protocol') + "//" + $(location).attr('hostname') + siteSearch;

to :

    var q = $(location).attr('protocol') + "//" +  siteSearch;

because you already define your hostname in this line:

    var siteSearch = "SiteB.com/search.aspx";

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.