loading a page in an inline frame

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • StumpY

    #1

    loading a page in an inline frame

    Hi
    I have a code which works ok, except I would like to load the specified file
    in an inline frame (I1) on the page instead of a whole new page if at all
    possible - any help appreciated!
    Here is the function in the <head>;

    <script type="text/javascript">

    function go()
    {
    location=docume nt.forms[0].PropPage.value
    }

    </script>

    .....and the code (form) which calls the function later on the page;

    <form>
    <p align="center">
    <select id="PropPage" onchange="go()" >
    <option>-Select Property Type-
    <option value="fincas.h tm">Fincas
    <option value="villas.h tm">Villas
    <option value="semideta ched.htm">Semi-detached
    <option value="apartmen ts.htm">Apartme nts
    <option value="plots.ht m">Land plots
    <option value="newdevel opments.htm">Ne w Developments
    </select>

    Thanks in advance

    Stumpy


  • Richard Cornford

    #2
    Re: loading a page in an inline frame

    "StumpY" <stumpydrivesa% 20datsun@hotmai l.com> wrote in message
    news:Buazb.2605 $RK.1272@news-binary.blueyond er.co.uk...[color=blue]
    >I have a code which works ok, except I would like to load the
    >specified file in an inline frame (I1) on the page instead of
    >a whole new page if at all possible - any help appreciated!
    > Here is the function in the <head>;
    >
    > <script type="text/javascript">
    >
    > function go()
    > {
    > location=docume nt.forms[0].PropPage.value[/color]

    Unqualified "location" will be resolved as the location property in the
    current global object (the window or frame on web browsers), if it
    exists. To navigate an IFRAME with this type of statement you need to
    assign the URL string to the location property in the IFRAME's global
    object. The IFRAME's global object (window/frame) should be found in the
    frames collection of the current window, either as a named property if
    the IFRAME has a name attribute (or, an ID attribute, but not on so many
    browsers), or as a numerically indexed property. So the location object
    of the IFRAME may be referred to as:-

    frames['iframeName'].location

    frames[0].location

    -for example (adjusting names/numbers to suite the context of the HTML
    in use).

    The value property of a SELECT element is not necessarily the best way
    of getting the value of the currently selected option. It works on most
    modern browsers (and is W3C HTML DOM specified) but the most reliable
    method of reading the value of the selected option is to use the
    selectedIndex property of the SELECT element to index its options
    collection and read the value property of the option that is selected
    directly:-

    var sel = document.forms[0].PropPage;
    if(sel.selected Index >= 0){ // -1 means no selection.
    frames['iframeName'].location = sel.options[sel.selectedInd ex].value;
    }
    [color=blue]
    > }
    >
    ></script>
    >
    >....and the code (form) which calls the function later on
    >the page;
    > <form>
    > <p align="center">
    > <select id="PropPage" onchange="go()" >[/color]

    Have you tested this with keyboard navigation of the SELECT element?
    Probably not, when you do so you might see a need to re-consider the use
    of the onchange event, probably a separate "Go" button to actually do
    the navigation would be better (or maybe a re-think of the whole idea
    and the replacement of this SELECT element with a list of links
    targeting the IFRAME)
    [color=blue]
    > <option>-Select Property Type-[/color]

    This OPTION element has no value attribute, no associated URL. So, if it
    is re-selected it will encourage the IFRAME to load a non-existent
    resource. As this option has the index zero as slight modification to
    the safety check I proposed above would avoid this option attempting to
    navigate the IFRAME:-

    if(sel.selected Index > 0){ //not -1 or zero.
    ...
    [color=blue]
    > <option value="fincas.h tm">Fincas
    > <option value="villas.h tm">Villas
    > <option value="semideta ched.htm">Semi-detached
    > <option value="apartmen ts.htm">Apartme nts
    > <option value="plots.ht m">Land plots
    > <option value="newdevel opments.htm">Ne w Developments
    > </select>[/color]

    Also, none of this is going to work at all if the user has JavaScript
    disabled or unavailable on their browser. That produces a dependency on
    JavaScript that is not necessitated by the apparent desired behaviour of
    this page.

    Richard.


    Comment

    Working...