SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Addict mcrumlish's Avatar
    Join Date
    Jan 2002
    Posts
    384
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    loading an iframe using a dropdown box

    Hi,

    I have a page that uses a SELECT box as a menu which loads the specified page when the user clicks go.

    However, I need to change this so that it will load the specified page to an iFrame which i have added to the code.

    Here is the main parts of my code:

    The JavaScript
    PHP Code:
    <SCRIPT LANGUAGE="JavaScript">
    function 
    formHandler(form){
    var 
    URL document.form.site.options[document.form.site.selectedIndex].valuetarget='main';
    window.location.href.target URL;
    }
    </SCRIPT> 
    The SELECT box:
    PHP Code:
    <form name="form">
    <
    select name="site" size=1>
    <
    option value="horseracing.php">Horse Racing Specials
    <option value="SoccerSpecials.php">Soccer Specials
    <option value="golfspecials.php">Golf Specials
    <option value="otherspecials.php">Other Specials
    </select> <input type=button value="Go" onClick="javascript:formHandler(this)"></form
    The iframe:
    PHP Code:
    <IFRAME SRC="welcome.html" name="main" WIDTH=600 HEIGHT=320 frameborder=0 border=0></IFRAME
    Any ideas? I have been searching forums and google but i cant find anything to sort out the problem for me.

    Any help is appreciated.

    Thanks in advance,

    Martin

  2. #2
    You want what? By when?? Milamber's Avatar
    Join Date
    Jan 2001
    Location
    California
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i imagine that you just need to find the DOM path to the iframe and change it's src attribute, just like doing that to a normal page.

    EDIT: Something like document.frames.["main"].src = url;

    However, be aware that this most likely will break in every browser but ie AND that iframes aren't supported all around.


    Why don't you just forward the people to those pages? Why hasel with iframes?
    -Jeff Minard | jrm.cc - Battlefield 2 Stats

  3. #3
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wouldn't you just change your script to read as follows?:
    PHP Code:
    <SCRIPT LANGUAGE="JavaScript"
    function 
    formHandler(form){ 
    var 
    URL document.form.site.options[document.form.site.selectedIndex].valuetarget='main'
    document.all.main.src URL;

    </SCRIPT> 
    Note that I've only changed the last line and assigned the URL value to the src property of the iFrame instead of the window ("main" being the name of your iFrame).


    Andy

  4. #4
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Milamber just beat me to responding.
    What he says about iFrames breaking in most browsers is probably true, but they do look neat.

    I used them recently on a company intranet site where I know that everyone uses an up-to-date version of IE so that's not a problem.

    You'll notice that I specified the DOM path as:
    document.ALL.main.src
    I read that as being the correct style recently. Possibly even on here although the URL escapes me for now - sorry.


    Andy


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
  •