SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Nov 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow search query to google as <iframe> source

    hello everyone

    I am trying to make a page which would take a "entered" on search query from the previous page and display results in google with that query in an <iframe> in the results.htm page.

    So if I enter the word "watches" into a textbox, the google search results would be displayed in an <iframe> in the results.htm page for the word "watches" with something like http://www.google.com/search?q= for "textValue".

    I have did set up a demo, but was having all kinds of problem s with displaying the appropriate query in an <iframe>, so at the moment the results page is without any iframes.

    here is the demo http://scratchpad.50webs.com/iframe

    I tried all sorts of stuff, played around with javascript, but nothing. Scanned a million forums through google, but still nothing.

    How can I make the <iframe> on the "results.htm" page to display the google search for the entered word, automatically when the page loads, and still have the textbox on results.htm fill up with the passed textbox value from the first page?

    thanks a bunch!!
    v

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So if I enter the word "watches" into a textbox
    On what page?

    the google search results would be displayed in an <iframe> in the results.htm page
    Is that on the same page you type watches on?

    for the word "watches" with something like http://www.google.com/search?q= for "textValue".
    "for textValue"? What does that mean?

  3. #3
    SitePoint Member
    Join Date
    Nov 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    thanks for replyin, and sorry for not being precise enough the first time.

    Taking into consideration the example at http://scratchpad.50webs.com/iframe/index.htm,

    If I enter a word "water" in the textbox on http://scratchpad.50webs.com/iframe/index.htm,

    the word "water" would be displayed in the textbox on the next page (http://scratchpad.50webs.com/iframe/results.htm),

    and the google search results for "water" in an <iframe> also on the results.htm page (http://scratchpad.50webs.com/iframe/results.htm)

    Passing the form text to the next page is already working, I just need to work on the <iframe>

    How do I get the iframe on the results.htm page to display the google search in an <iframe> for a word that was entered in the index.htm page?

    thanks a lot.

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try using:
    Code:
    window.frames["iframeName"].location.href = 
    "http://www.google.com/search?hl=en&q=" 
    + inputVal 
    + "&btnG=Google+Search";
    You have to wait until after the page loads to access an html element, so put that inside a window.onload function.

    It seems like it would be easier to use a submit button on page1, and then have a server side script( e.g. php) do the work. When the user clicks on the image, you are making a request for page2 from the server anyway . Usually javascript is used to do things that avoid reloading a page in the brower--that's the whole point.

  5. #5
    SitePoint Member
    Join Date
    Nov 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by 7stud View Post
    Try using:
    Code:
    window.frames["iframeName"].location.href = 
    "http://www.google.com/search?hl=en&q=" 
    + inputVal 
    + "&btnG=Google+Search";
    You have to wait until after the page loads to access an html element, so put that inside a window.onload function.

    It seems like it would be easier to use a submit button on page1, and then have a server side script( e.g. php) do the work. When the user clicks on the image, you are making a request for page2 from the server anyway . Usually javascript is used to do things that avoid reloading a page in the brower--that's the whole point.
    I tried putting this in http://scratchpad.50webs.com/iframe/results.htm, but got errors.

    I'm not really good with javascript, so have no clue how to nest the code into window.onload! here s the code I tried:

    Code:
    <html>
    <script>
    window.frames["iframeName"].location.href = 
    "http://www.google.com/search?hl=en&q=" 
    + inputVal 
    + "&btnG=Google+Search";
    </script>
    <body>
    <form name="formName"><input type="text" name="textName"></form>
    <script language="JavaScript"><!--
    document.formName.textName.value = location.search.substring(1);
    //--></script>
    
    <iframe name="iframeName" src="" border="0" height="100" width="100"></iframe>
    
    </body>
    </html>




    Quote Originally Posted by 7stud View Post
    It seems like it would be easier to use a submit button on page1, and then have a server side script( e.g. php) do the work
    Instead, we can try with this :
    I did dig out an example which does pass your query to <iframes> with an image button, using "getElementById".

    have a look: http://scratchpad.50webs.com/frames/index.htm

    But, the only problem is, that here the textbox value is passed on to TWO <iframes>, whereas, I want it in only ONE <iframe>, the one with the google search.

    have a look at the .js file http://scratchpad.50webs.com/frames/search.js(you will have to save it directly, dosent allow viewing directly from the URL) and also the source code of http://scratchpad.50webs.com/frames/results.htm

    And another thing, the results.htm page in the initial example (http://scratchpad.50webs.com/iframe) uses the value right after the "?" question mark after the URL to write down the value in the textbox.

    But the second example I provided (http://scratchpad.50webs.com/frames/index.htm, has "src1=" and "src2=" in its URL.

    How do you modify the code, so that instead of displaying TWO <iframes>, it would display only ONE, and instead of "src=1", it would just have the textbox value entered on index.htm, so that the textbox can read the passed on value in the results.htm page? (like in the first example: http://scratchpad.50webs.com/iframe/index.htm)

    thanks again.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •