javascript multi option selected & iframe src on page refresh

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • omar999
    New Member
    • Mar 2010
    • 120

    javascript multi option selected & iframe src on page refresh

    i'm working with a city select option, a hotel select option & an iframe. the hotel select option is populated depending on the chosen city which then updates the iframe src. this is all working fine.

    the trouble im having is that when the page is refreshed, normal f5 way, the hotel option changes whereas the city option & the iframe src remains the same??

    this problem does not occur on a force refresh via control + f5 as then both select options & iframe src revert to their original state.

    I don't want the city option to change upon a normal page refresh. how do I go about this?

    below are the city, hotel select options & iframe
    Code:
        <form name="hotelslist" id="hotelslist">
            <select id="cities" name="cities" onChange="hotel_list(hotelslist.cities.selectedIndex);loadHotel();">
              <option value="Baddeck">Baddeck</option>
              <option value="Banff">Banff</option>
            </select>
        <select id="hotelnames" name="hotelnames" onChange="loadHotel();">
              <option value="Inverary Resort, Baddeck">Inverary Resort, Baddeck</option>
            </select>
          </form>
    
    <iframe name="hotelframe" id="hotelframe" src="http://www.google.com" scrolling="no" width="660" height="1000" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0"> <p>Your browser does not support iframes.</p> </iframe>
    below is my javascript functions
    Code:
    function loadHotel() { 
        var destURL = document.hotelslist.hotelnames.options[document.hotelslist.hotelnames.selectedIndex].value; 
    		window.frames["hotelframe"].location = destURL; }
    
    var i;
    function hotel_list(i){
    var hotelslist = document.getElementById("hotelslist");
    	hotelslist.hotelnames.options.length=0;
    	
    switch(i)
    {	
    case 0: //Baddeck
    hotelslist.hotelnames.options[0] =new  Option('Inverary Resort, Baddeck','http://www.test0.com');
    break;
    case 1: //Banff
    hotelslist.hotelnames.options[0] =new  Option('Banff Caribou Lodge & Spa','http://www.test1.com');
    hotelslist.hotelnames.options[1] =new  Option('Banff Ptarmigan Inn','http://www.test2.com');
    hotelslist.hotelnames.options[2] =new  Option('Banff Rocky Mountain Resort','http://www.test3.com');
    hotelslist.hotelnames.options[3] =new  Option('The Rimrock Resort','http://www.test4.com');
    hotelslist.hotelnames.options[4] =new  Option('Fairmont Banff Springs','http://www.test5.com/');
    break;
    }
    }
    can some one please advise on a cross browser solution?

    thanks in advance.
    Omar.
  • omar999
    New Member
    • Mar 2010
    • 120

    #2
    can anyone advise?

    Comment

    • gits
      Recognized Expert Moderator Expert
      • May 2007
      • 5390

      #3
      so on a refresh you want to preserve the hotellist and -names options? ... you might use a cookie or a serverside solution ...

      Comment

      • omar999
        New Member
        • Mar 2010
        • 120

        #4
        hi gits - thanks for your reply.

        thats right, in essence I want the city, hotel selects & iframe to ignore the page refresh and not do anything. i have read a little that you cant disable the browser refresh option so moving on...

        can you please advise as to how I can use a cookie? my scripting skills are quite newbie

        thanks in advance

        Comment

        • gits
          Recognized Expert Moderator Expert
          • May 2007
          • 5390

          #5
          you might have a look here for a start ...

          kind regards

          Comment

          Working...