#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    6
    Rep Power
    0

    JavaScript - Hyperlink in Iframe- Please help


    I am attempting to use a dropdown box to open a hyperlink in an Iframe.

    So far I can get the hyperlink to open in a new page but I would like to open it on the same page.

    Any help would be most grateful

    The code I have so far is:

    <html>
    <head>
    <link rel="stylesheet" href="prui.css" type="text/css">
    <script language="JavaScript">
    <!--
    function gotoLink(form) {
    var OptionIndex=form.ListBoxURL.selectedIndex;
    parent.location = form.ListBoxURL.options[OptionIndex].value;}
    //-->
    </script>
    </head>


    <body>
    <br>
    <form name="AutoListBox">
    <p>What type of work do you want to see requests for?

    <select name="ListBoxURL" size="1" language="javascript" onchange="gotoLink(this.form);">
    <option selected>Select</option>
    <option value="request.asp">Webtrends Report</option>
    <option value="request.asp">eCard</option>
    <option value="request.asp">Banner</option>
    <option value="request.asp">Online Form</option>
    </select></p>

    <iFrame name = "main1">

    <iFrame>

    </body>
    </html>
  2. #2
  3. Senior Polecat
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Jersey (the original version)
    Posts
    210
    Rep Power
    12
    you were nearly there ... all yo need to do is change the code a little:

    first the iframe tag:

    <iFrame name = "main1"> becomes <iFrame id="main1">

    (Note: Name is to be deprecated in XHTM1.1 so use ID where ever possible)

    then modify the javascript to reference the id of the iframe:

    parent.location = form.ListBoxURL.options[OptionIndex].value;}

    becomes

    main1.location = form.ListBoxURL.options[OptionIndex].value;}

    as you can see all you change is the id prefixing the .location statement.

    Hope that helps

    Icy
    Quidquid latine dictum sit, altum viditur.

    http://www.XSet.co.uk
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    6
    Rep Power
    0

    Thanks


    Excellent, thanks loads.

IMN logo majestic logo threadwatch logo seochat tools logo