473,396 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

asp cookie to retain multiple select option state on page refresh

120 100+
I have a 'city' select dropdown which populates a 'hotel' select dropdown via js. then using an onchange event handler on the 'hotel' select to populate the content of an iframe. all working so far.

problem is when I refresh the page I lose the current state of the selected city, hotel.

from what I've read I need to use a cookie to retain the state. can someone please advise on how I can go about this?

Expand|Select|Wrap|Line Numbers
  1. function loadHotel() { 
  2.     var destURL = document.hotelslist.hotelnames.options[document.hotelslist.hotelnames.selectedIndex].value; 
  3.         window.frames["hotelframe"].location = destURL; }
  4.  
  5. var i;
  6. function hotel_list(i){
  7. var hotelslist = document.getElementById("hotelslist");
  8.     hotelslist.hotelnames.options.length=0;
  9.  
  10. switch(i)
  11. {    
  12. case 0: //Baddeck
  13. hotelslist.hotelnames.options[0] =new  Option('Inverary Resort, Baddeck','http://www.canadianaffair.com/en/hotels/atlantic-canada/baddeck/inverary-resort/');
  14. break;
  15. case 1: //Banff
  16. hotelslist.hotelnames.options[0] =new  Option('Banff Caribou Lodge & Spa','http://www.canadianaffair.com/en/hotels/alberta/banff/banff-caribou-lodge-and-spa/');
  17. hotelslist.hotelnames.options[1] =new  Option('Banff Ptarmigan Inn','http://www.canadianaffair.com/en/hotels/alberta/banff/banff-ptarmigan-inn/');
  18. break;
  19. case 2: //Calgary
  20. hotelslist.hotelnames.options[0] =new  Option('Sandman - Calgary Downtown','http://www.canadianaffair.com/en/hotels/alberta/calgary/sandman-calgary-downtown/');
  21. hotelslist.hotelnames.options[1] =new  Option('The Westin Calgary','http://www.canadianaffair.com/en/hotels/alberta/calgary/the-westin-calgary/');
  22. break;
  23. }
  24. }
  25.  
  26. <td class="hotelslisttd">
  27. <form name="hotelslist" id="hotelslist">
  28. <select id="cities" name="cities" onChange="hotel_list(hotelslist.cities.selectedIndex);loadHotel();">
  29. <option value="Baddeck">Baddeck</option>
  30. <option value="Banff">Banff</option>
  31. <option value="Calgary">Calgary</option>
  32. </select>
  33. </td>
  34. <td class="hotelnamestd">
  35. <select id="hotelnames" name="hotelnames" onchange="loadHotel();";>
  36. <option value="Inverary Resort, Baddeck">Inverary Resort, Baddeck</option>
  37. </select>
  38. </form></td>
  39.  
  40. <iframe name="hotelframe" id="hotelframe" src="http://www.canadianaffair.com/en/hotels/atlantic-canada/baddeck/inverary-resort/" scrolling="no" width="560" height="1000" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0"> <p>Your browser does not support iframes.</p> </iframe>
  41.  
  42.  
thanks in advance
Omar.
Apr 19 '10 #1
15 3221
jhardman
3,406 Expert 2GB
yeah, setting a cookie would work, I would do it on the iFrame page
Expand|Select|Wrap|Line Numbers
  1. response.cookies("city") = request.form("city")
or you could just set it as a session variable
Expand|Select|Wrap|Line Numbers
  1. session("city") = request.form("city")
Jared
Apr 20 '10 #2
omar999
120 100+
thank you for starting me off Jared.
I've added this to top of the page containing form, selects & iframe
Expand|Select|Wrap|Line Numbers
  1. <%
  2. response.cookies("cities") = request.form("cities")
  3. %>
then within the iframe src page I've added this to the top of the page
Expand|Select|Wrap|Line Numbers
  1. <%
  2. city=Request.Cookies("cities")
  3. response.write("cities=" & city)
  4. %>
  5.  
but it's not outputting the selected city? has this something to do with my iframe src?...
Apr 20 '10 #3
jhardman
3,406 Expert 2GB
@omar999
it is the iframe page that gets reloaded when the city is selected, right? then you need to set the city cookie there.

Jared
Apr 20 '10 #4
omar999
120 100+
hi jared - the iframe reloads when city & hotel are selected or "onchange".

so if i understand correct do you mean i should set and retrieve the cookie within the iframe?
Apr 20 '10 #5
jhardman
3,406 Expert 2GB
@jhardman
yes, at least you need to set it there within the iframe (that's where the city input is sent when the input is changed, so that's the best place to set the cookie).

If I understand what you are asking, you would need to retrieve it on the main page (if it exists) - if the cookie exists when the main page is being loaded, then you have previously changed the hotel and city selects and now are just refreshing that page. Does this make sense?

Jared
Apr 20 '10 #6
omar999
120 100+
ok cool I will set & retrieve cookie within iframe and will post back progress.

yea basically on a page refresh I dont want the city, hotel & iframe src to change from what the user may have already selected - instead I want to retain the selected state if the page is refreshed.

Omar.
Apr 20 '10 #7
omar999
120 100+
set & retreived cookie within iframe src but no joy. to clarify - this is my setup;

default.asp [contains form, selects & iframe - (iframe src pointing to hotel1.asp)]
then the function hotel_list populates the iframe src of every other hotel - e.g hotel2.asp, hotel3.asp..etc

not sure where to go from here... please advise
Apr 20 '10 #8
jhardman
3,406 Expert 2GB
@omar999
YOU DO NOT NEED TO RETRIEVE THE COOKIE IN THE IFRAME. YOU NEED TO SET THE COOKIE IN THE IFRAME AND RETRIEVE IT IN THE MAIN PAGE. IT WON"T WORK IN ANY OTHER COMBINATION.

Jared
Apr 21 '10 #9
omar999
120 100+
morning Jared

thanks for clarifying - my brain is a little fried so I'm finding it hard to process anything. it doesnt help when I've been working 15 hour shifts 2 days in a row!

I'll give this a go and will post up progress. thank u
Apr 21 '10 #10
omar999
120 100+
ok I've set the cookie in the iframe as
Expand|Select|Wrap|Line Numbers
  1. <%response.cookies("cities") = request.form("cities")%>
and to retrieve in main page as
Expand|Select|Wrap|Line Numbers
  1. <%city=Request.Cookies("cities")
  2. response.write("cities=" & city)%>
but still no joy. I've tried refreshing the page and selecting different hotels but the city value isnt being displayed on the page?
Apr 21 '10 #11
jhardman
3,406 Expert 2GB
@omar999
try to list everything in cookies just to clarify whether cookies are being passed:
Expand|Select|Wrap|Line Numbers
  1. response.write "<p>Cookies:" & vbNewLine
  2. for each x in request.cookies
  3.    response.write x & ": " & request.cookies(x) & "<br>" & vbNewLine
  4. next
Jared
Apr 21 '10 #12
omar999
120 100+
hi jared

I added this code to the main page and the page is displaying this [i've edited out the website address]

Expand|Select|Wrap|Line Numbers
  1. Cookies: __utma: 228366991.358854659.1270736550.1271799773.1271836851.52
  2. __utmz: 228366991%2E1270736550%2E1%2E1%2Eutmcsr=%28direct%29%7Cutmccn%3D%28direct%29%7Cutmcmd%3D%28none%29
  3. cities:
  4. name:
  5. hasVisited: 0
  6. __utmc: 1
  7. X-Mapping-gdmmbdpb: B7FC7B07D3E4A6F2410CF7CBA64192E5
  8. __utmb: 228366991.323.10.1271836851
  9. profile_referrer: websitename
  10. websitenameGAId: UA-6277292-1
  11. firstname: Alex
  12. hotelnames: 
  13.  
not sure what this means?
Apr 22 '10 #13
jhardman
3,406 Expert 2GB
a lot of it you can just ignore, but on the 5 you set (cities, name, hasVisited, firstname, hotelnames) only two had values, the rest of the cookies were set, but had no values. I bet that when you refresh the page you are also clearing the values of those cookies. When you go to set the cookies check to see if you are setting an empty value:
Expand|Select|Wrap|Line Numbers
  1. if request.form("cities") <> "" then
  2.    response.cookies("cities") = request.form("cities")
  3. end if 
Jared
Apr 22 '10 #14
omar999
120 100+
hi jared

I added
Expand|Select|Wrap|Line Numbers
  1. if request.form("cities") <> "" then
  2.    response.cookies("cities") = request.form("cities")
  3. end if 
to the page and refreshed it and the page still outputs this same message
Expand|Select|Wrap|Line Numbers
  1. Cookies: __utma: 228366991.358854659.1270736550.1271799773.1271836851.52
  2. __utmz: 228366991%2E1270736550%2E1%2E1%2Eutmcsr=%28direct%29%7Cutmccn%3D%28direct%29%7Cutmcmd%3D%28none%29
  3. cities:
  4. name:
  5. hasVisited: 0
  6. __utmc: 1
  7. X-Mapping-gdmmbdpb: B7FC7B07D3E4A6F2410CF7CBA64192E5
  8. __utmb: 228366991.323.10.1271836851
  9. profile_referrer: websitename
  10. websitenameGAId: UA-6277292-1
  11. firstname: Alex
  12. hotelnames: 
  13.  
i wish there was a senior developer at my company. this sucks.
Apr 23 '10 #15
jhardman
3,406 Expert 2GB
is this live? Can I browse there to check it?

Jared
Apr 23 '10 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: ehendrikd | last post by:
hi all i need some clarification on how the php session work in relation to cookies. we have a web site where users need to log in. a few of our users were having troubles with their browser...
4
by: darrel | last post by:
I'm having some problems getting a cookie set on a button click. Here is my function: Private Sub buttonSaveSettings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles...
3
by: ANTISPAM_garycnew_ANTISPAM | last post by:
What is the simplest way to retain the last option value selected in an html select object using javascript? I am currently using a server-side cgi language to accomplish this task, but it adds...
2
by: areef.islam | last post by:
Hi, I am kinda new to javascript and I am having this problem with selecting multiple options from a select tag. Hope someone can help me out here. here is my code...
2
by: Griff | last post by:
Hi I have an HTML search page that contains a drop-down box with approximately 78,000 items in it. The actual content of this select box varies depending upon some of the parameters a user...
5
by: Jon Davis | last post by:
Does anyone know of a best practices or common practices article URL for implementing a sessionless web farm while still managing user logins, etc.? I just got hired by a company that told me...
3
by: Dan | last post by:
Hi, I am trying to refresh the cookie to make sure the timeout is reset by simply calling a blank page on my site. I am doing this because I have an external site hosted in my web that isn't...
4
by: rn5a | last post by:
A Form has 2 select lists. The 1st one whose size is 5 (meaning 5 options are shown at any given time) allows multiple selection whereas the 2nd one allows only 1 option to be selected at a time. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.