Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: iframe and submit button

  1. #1
    Join Date
    May 2006
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default iframe and submit button

    hello evrey one, i was hopeing to build a search engine on my site that would search other sites like yahoo , google ,ect.. i've been having one problem with it tho , im trying to get the search results to open in an iframe but all my efforts do this have been in vain , i should mention that im a noob at this , that siad here is the code
    this is my .js file (test.js)
    Code:
    function doSearch( selectedIndex, searchTerm ) {
       if ( selectedIndex < 0 ) {
          alert("Please select a search engine!");
          return false;
       } else if ( searchTerm == "" ) {
          alert("No search term!");
          return false;
       }
       window.open( SEARCH_DATA[selectedIndex][1] , SEARCH_DATA[selectedIndex][0] );
    }
    
    
    
    function engine1( selectedIndex, searchTerm ) 
    {
       SEARCH_DATA= new Array(73);
       <!--SEARCH_DATA[value]= new Array( window name , url ) -->
       SEARCH_DATA[1]= new Array("yahoo","http://search.yahoo.com/search?p="+escape(searchTerm)+"&sm=Yahoo%21+Search&fr=FP-tab-web-t&toggle=1&cop=&ei=UTF-8");
    
        
    doSearch( selectedIndex, searchTerm );
       return true;
    }
    this is the form code
    Code:
    <script language=JavaScript src="test.js" type=text/javascript></script>
    <div align="center"> 
    <form name="searchForm1" action="" onSubmit="javascript:engine1(this.engine.options[this.engine.selectedIndex].value,this.go.value); return false;">
    <select name="engine" class="drop_down">
    <option value="-1" selected>Torrent Search</option>
    <option value="1">yahoo</option>
    
    </select>
    <input name="go" class="text_field" size="20" maxlength="35" />
    <input name="submit" type="submit" class="search_button" value="Search" />
    </form>
    this is my iframe statment
    Code:
    <iframe id="inpage"  style="width:600px;height:400px" src="http://www.google.com"></iframe>
    im trying to set it up so that when the search button is clicked it would open the search results in the iframe. any comments will be appreciated and thanx in advance

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Change:

    Code:
    window.open( SEARCH_DATA[selectedIndex][1] , SEARCH_DATA[selectedIndex][0] );
    to:

    Code:
    inpage.location.href= SEARCH_DATA[selectedIndex][1] , SEARCH_DATA[selectedIndex][0] ;
    There are probably many efficiency and error avoiding strategies that could be used as well but, the above change made it work.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Ouch.
    Code:
    document.frames['inpage'].location.href= SEARCH_DATA[selectedIndex][1] , SEARCH_DATA[selectedIndex][0] ;
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by Twey
    Ouch.
    Code:
    document.frames['inpage'].location.href= SEARCH_DATA[selectedIndex][1] , SEARCH_DATA[selectedIndex][0] ;
    Quote Originally Posted by FF Javascript Console
    document.frames has no properties
    Look before you leap, as I should have. The iframe's id is inpage, so for modern browsers we need:

    Code:
    document.getElementById('inpage').src= SEARCH_DATA[selectedIndex][1] , SEARCH_DATA[selectedIndex][0] ;
    I tried various variations on changing id to name but it didn't like them in FF. I may have missed the correct one.

    At least my code and your 'correction' both worked in IE6.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Oh, if we change:

    HTML Code:
    <iframe id="inpage"  style="width:600px;height:400px" src="http://www.google.com"></iframe>
    to:

    HTML Code:
    <iframe name="inpage"  style="width:600px;height:400px" src="http://www.google.com"></iframe>
    We can do this:

    Code:
    window.open( SEARCH_DATA[selectedIndex][1], 'inpage' ) ;
    The ',SEARCH_DATA[selectedIndex][0]' was meaningless in our other versions, as far as I can tell, just a declaration of a variable. In the original, it was the name of the window, though I suppose it wasn't meant to be.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Quote Originally Posted by John
    Look before you leap, as I should have.
    Whoops... it's window.frames. My mistake. However, Firefox throws a series of exceptions when I try to set its source:
    Code:
    Error: uncaught exception: [Exception... ""  nsresult: "0x804b000a (<unknown>)"  location: "JS frame :: javascript:alert(window.frames['cw'].location="yahoo.com"); :: <TOP_LEVEL> :: line 1"  data: no]
    Code:
    Error: uncaught exception: Permission denied to set property Window.src
    ... which confused me slightly. I understand why this happens when trying to get the source, but why for a setter?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I'm not clear on the whys and wherefores but, going by what works, when you access an object like a frame as a window, you need to use its location property. When you access it as an element, use its source attribute. Kinda makes sense:

    Code:
    window.frames['inpage'].location.href = SEARCH_DATA[selectedIndex][1];
    That's using the iframe with its name (not its id) set to 'inpage'. I'd forgotten about that window vs document thing. If the two of us have such trouble, you can imagine why it is so tough for the folks we help.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    when you access an object like a frame as a window, you need to use its location property. When you access it as an element, use its source attribute.
    That makes sense, but I still don't see the security risk in setting the location as we are (mistakenly) accustomed to doing with window.location.
    If the two of us have such trouble, you can imagine why it is so tough for the folks we help.
    Hah, yes
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by Twey
    That makes sense, but I still don't see the security risk in setting the location as we are (mistakenly) accustomed to doing with window.location.Hah, yes
    I'm not sure I follow you. The location can be set when it is a window, the source can be set when it is an element. I believe these two can also be retrieved. Any security violation that occurs, say - accessing the source of a window or the location of an element, may be spurious, more a reflection of the fact that these objects technically do not possess the attribute or property in question and/or if they do, it represents something other than what you are imagining that it does.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    For example,
    Code:
    window.location = "www.google.com";
    will work fine. However,
    Code:
    window.frames[0].location = "www.google.com";
    will throw a security exception. I don't see why.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •