/    Sign up×
Community /Pin to ProfileBookmark

Dynamic dropdowns not maintaining state on BACK

i am having this problem(but only with IE6, NS4.76 works)too, and when i click my ‘back’ link,

[code=php]
<a href = ‘java script:history.back();’>Change Order</a>

[/code]

the second dropdown is not populated, there are no values to select other than the default.
When the page is originally submitted, a confirmation page is loaded. it is from here to the original order page where i lose the values in the dropdowns.

isn’t there a simple way to fix this? why wouldit work in Netscape 4.76 but not a more modern browser (IE 6)?
here’s the dropdowns:
FIRST DROPDOWN

[code=php]
<select name=”EventLocation” onChange=”fillSelectFromArray(this.form.PreferredRoom, ((this.selectedIndex == -1) ? null : team[this.selectedIndex-1]));”>
<option value=”eventloc”>Select a Location…</option>
<option>FirstOption</option>
<option>SecondOption</option>
</select>

[/code]

SECOND DROPDOWN

[code=php]
<select name=”PreferredRoom”>
<option value=”Select a room…”,”VP”>Select a room…</option>
</select>

[/code]

JAVASCRIPT THAT MAKES IT WORK

[code=php]
<!– Begin
team = new Array(
new Array(
new Array(“Select a room…”, “VP”),
new Array(“Post Parade”, “Post Parade”),
new Array(“Favourites”, “Favourites”),
new Array(“International Room”, “International Room”),
new Array(“International Room A”, “International Room A”),
new Array(“International Room B”, “International Room B”),
new Array(“Munnings Room”, “Munnings Room”),
new Array(“Dancer”, “Dancer”),
new Array(“Post Parade”, “Post Parade”),
new Array(“Trackside Tent”, “Trackside Tent”),
new Array(“Wood Club”, “Wood Club”)
),
new Array(
new Array(“Select a room…”, “VP”),
new Array(“Directors Lounge”, “Directors Lounge”),
new Array(“Sports Lounge”, “Sports Lounge”),
new Array(“Terrace Dining Room”, “Terrace Dining Room”),
new Array(“Trackside Lounge”, “Trackside Lounge”)
)
);
function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {
var i, j;
var prompt;
// empty existing items
for (i = selectCtrl.options.length; i >= 0; i–) {
selectCtrl.options[i] = null;
}
prompt = (itemArray != null) ? goodPrompt : badPrompt;
if (prompt == null) {
j = 0;
}
else {
selectCtrl.options[0] = new Option(prompt);
j = 1;
}
if (itemArray != null) {
// add new items
for (i = 0; i < itemArray.length; i++) {
selectCtrl.options[j] = new Option(itemArray[i][0]);
if (itemArray[i][1] != null) {
selectCtrl.options[j].value = itemArray[i][1];
}
j++;
}
// select first item (prompt) for sub list
selectCtrl.options[0].selected = true;
}
}
// End –>

[/code]

Any help is greatly appreciated!!!

THANKS!!!

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@JonaOct 22.2003 — [font=arial][color=maroon]Try using whatever server-side language you are utilizing already to keep cache loaded in the browser for the past two pages; there is no other way to do it, that I'm aware of...[/color][/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@sanjuTauthorOct 22.2003 — i need to use the server-side language (java servlets) to do this?

thanks. I'll look it up.
Copy linkTweet thisAlerts:
@JonaOct 22.2003 — [i]Originally posted by sanjuT [/i]

[B]i need to use the server-side language (java servlets) to do this?[/B][/QUOTE]


[font=arial][color=maroon]It doesn't have to be Java, it can be PHP, ASP, CGI, etc. What language are you currently using?[/color][/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@sanjuTauthorOct 22.2003 — I use Java servlets to process the form, javascript is extensively used on the client-side for validation.
Copy linkTweet thisAlerts:
@JonaOct 22.2003 — [font=arial][color=maroon]Okay, in that case, you would look for information on keeping cache in Java servlets.[/color][/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@hawk6977Aug 25.2004 — I know this question was posted a year ago, but I needed the answer recently. When the solution was "save it in the cache," I came up with the following:

ADD:

function myRestore() {

var t=document.myForm.dropDown2.selectedIndex;

fillSelectFromArray(document.myForm.DropDown2, ((document.myForm.dropDown1.selectedIndex == -1) ? null :

category[document.myForm.dropDown1.selectedIndex-1]));

document.myform.dropDown2.selectedIndex=t;

}

AND:

<body onload="myRestore()">

This will repopulate the second dropdown when you return to the page.

HOWEVER,

The second dropdown will still not have it's selected index set correctly, unless you add enough

<option></option>

(empty option pairs) to account for the longest list you have for it.

I didn't try generating these dynamically with javascript document.write statements, and I suspect it wouldn't work.
×

Success!

Help @sanjuT spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...