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? -
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.canadianaffair.com/en/hotels/atlantic-canada/baddeck/inverary-resort/');
-
break;
-
case 1: //Banff
-
hotelslist.hotelnames.options[0] =new Option('Banff Caribou Lodge & Spa','http://www.canadianaffair.com/en/hotels/alberta/banff/banff-caribou-lodge-and-spa/');
-
hotelslist.hotelnames.options[1] =new Option('Banff Ptarmigan Inn','http://www.canadianaffair.com/en/hotels/alberta/banff/banff-ptarmigan-inn/');
-
break;
-
case 2: //Calgary
-
hotelslist.hotelnames.options[0] =new Option('Sandman - Calgary Downtown','http://www.canadianaffair.com/en/hotels/alberta/calgary/sandman-calgary-downtown/');
-
hotelslist.hotelnames.options[1] =new Option('The Westin Calgary','http://www.canadianaffair.com/en/hotels/alberta/calgary/the-westin-calgary/');
-
break;
-
}
-
}
-
-
<td class="hotelslisttd">
-
<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>
-
<option value="Calgary">Calgary</option>
-
</select>
-
</td>
-
<td class="hotelnamestd">
-
<select id="hotelnames" name="hotelnames" onchange="loadHotel();";>
-
<option value="Inverary Resort, Baddeck">Inverary Resort, Baddeck</option>
-
</select>
-
</form></td>
-
-
<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>
-
-
thanks in advance
Omar.
15 3221
yeah, setting a cookie would work, I would do it on the iFrame page - response.cookies("city") = request.form("city")
or you could just set it as a session variable - session("city") = request.form("city")
Jared
thank you for starting me off Jared.
I've added this to top of the page containing form, selects & iframe -
<%
-
response.cookies("cities") = request.form("cities")
-
%>
then within the iframe src page I've added this to the top of the page - <%
-
city=Request.Cookies("cities")
-
response.write("cities=" & city)
-
%>
-
but it's not outputting the selected city? has this something to do with my iframe src?...
@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
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?
@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
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.
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
@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
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
ok I've set the cookie in the iframe as - <%response.cookies("cities") = request.form("cities")%>
and to retrieve in main page as - <%city=Request.Cookies("cities")
-
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?
@omar999
try to list everything in cookies just to clarify whether cookies are being passed: - response.write "<p>Cookies:" & vbNewLine
-
for each x in request.cookies
-
response.write x & ": " & request.cookies(x) & "<br>" & vbNewLine
-
next
Jared
hi jared
I added this code to the main page and the page is displaying this [i've edited out the website address] -
Cookies: __utma: 228366991.358854659.1270736550.1271799773.1271836851.52
-
__utmz: 228366991%2E1270736550%2E1%2E1%2Eutmcsr=%28direct%29%7Cutmccn%3D%28direct%29%7Cutmcmd%3D%28none%29
-
cities:
-
name:
-
hasVisited: 0
-
__utmc: 1
-
X-Mapping-gdmmbdpb: B7FC7B07D3E4A6F2410CF7CBA64192E5
-
__utmb: 228366991.323.10.1271836851
-
profile_referrer: websitename
-
websitenameGAId: UA-6277292-1
-
firstname: Alex
-
hotelnames:
-
not sure what this means?
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: - if request.form("cities") <> "" then
-
response.cookies("cities") = request.form("cities")
-
end if
Jared
hi jared
I added - if request.form("cities") <> "" then
-
response.cookies("cities") = request.form("cities")
-
end if
to the page and refreshed it and the page still outputs this same message -
Cookies: __utma: 228366991.358854659.1270736550.1271799773.1271836851.52
-
__utmz: 228366991%2E1270736550%2E1%2E1%2Eutmcsr=%28direct%29%7Cutmccn%3D%28direct%29%7Cutmcmd%3D%28none%29
-
cities:
-
name:
-
hasVisited: 0
-
__utmc: 1
-
X-Mapping-gdmmbdpb: B7FC7B07D3E4A6F2410CF7CBA64192E5
-
__utmb: 228366991.323.10.1271836851
-
profile_referrer: websitename
-
websitenameGAId: UA-6277292-1
-
firstname: Alex
-
hotelnames:
-
i wish there was a senior developer at my company. this sucks.
is this live? Can I browse there to check it?
Jared
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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.
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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...
| |