0

I am currently working on the standard 'Yahoo Hosted Web Search' scripting but having a few issues.

On the search box on my homepage (index.html) you enter a query then hit submit for a yahoo search to return results on the same page.

This submit action triggers the yahoo javascript on the homepage to return search results on the same page via the placing of an appropriate div within which a results iframe loads.

THE FULL PROCESS SCRIPTING IS AS FOLLOWS:

=============================================================

< form id="searchform" onsubmit="return search();">

        <input type="text" id="searchbox" size="10" />
        <input type="submit" value="Submit"/>
    </form >

:

=====================================================================

    <script type="text/javascript">
        function search() {
            YHS.search(document.getElementById("searchbox").value);
    </script>

=====================================================================

EXTRACT COMMAND:::::::::::::::::::

dom_id: "bossDiv", // id of div tag under which BOSS Hosted Search iframe will be rendered

=====================================================================

    <div id="bossDiv">
    </div>

This is the empty div tag within which the BOSS Hosted Search experience will be shown. You will need to replace the with this div id ('bossDiv') in the Javascript code snippet

===============

Now basically i would like to ensure that my results are presented on a 2nd page not the homepage. The issue is the DIV TAG: ID 'bossDiv' loads the iframe on the homepage.. is there anyway i can insert this DIV into say results.html and have the homepage somehow command the div on the results.html page to display the search results there instead?

Been trying so hard to try form actions etc but the only way i can see that this will work is if i simply insert the div into the results.html page and somehow tell the yahoo javascript on index.html where to find the DIV or redirect the page to find and trigger the DIV ?? Does anyone know of a way to tell a java where to find a div on another page to trigger and action it there upon a query search submit..?

Please help its been wrecking my brain for at least 2 weeks now and i dont know what steps to take anymore from reading alot of jumble online :(

Thank all!

1 Answers1

0

You can't access another page via javascript - a common approach for searching is to use a QueryString

How can I get query string values in JavaScript?

Community
  • 1
  • 1
Rob Hardy
  • 1,821
  • 15
  • 15
  • Thank you for your fast reply! Would there be anyway of triggering the DIV? – Leylah Richi Oct 10 '12 at 13:53
  • It looks like you'll need to implement the search form yourself on your first page and get it to send you to your second page with the second page. You can use either QueryStrings in the URL or if you're using a server side scripting language which can intercept the post then you can intercept the search string in a form post if you prefer. Once on the second page, capture the variable from the first page (from the URL or rendered on page by server side script) and pass that to the yahoo search API as the search string. - this should 'trigger' the div on the second page to render the iframe. – Rob Hardy Oct 10 '12 at 14:34
  • Thanks Rob, Thats spot on! In the instance of using QueryStrings in my url: After a user has searched say CARS in my search box and hit submit, it can then either give WEBURL.COM/?search=CARS or if i use the:
    and upon a submitted query that brings back: WEBURL.COM/search.php?search=cars I know its a long shot but i dont suppose you could advise on how i could caputure the search variable from the URL and pass it to the search API as the search string in order to trigger the results? Sorry 2 be of hassle! @Rob-Hardy
    – Leylah Richi Oct 12 '12 at 14:36
  • No worries - say it in votes =D You can extract query strings using `document.location.search` in JavaScript. See http://pastebin.com/w18r8fFM for a simplified example – Rob Hardy Oct 12 '12 at 21:55
  • Thank you :). i am right in thinking that i paste in your example of: between – Leylah Richi Oct 12 '12 at 23:54
  • then i just somehow have two onload= commands to 1) run your java script then 2) run the yahoo script of search() in my example.. would that then pass the query into the yahoo search results? ill gladly make a paypal donation too if i can get it too work.. its just been dragged out so long as its a new area for me damn it :) – Leylah Richi Oct 12 '12 at 23:58
  • You can place the script inline or put it in its own .js file andreference the script. I'm not really sure how the yahoo API works, but using that script and looking for the 'search' querystring, you can pass `GetQueryString('search')` to whatever initializes your yahoo search to create the iframe. – Rob Hardy Oct 13 '12 at 10:44