rickya100 3 Junior Poster in Training

Hey everyone,

The problem I'm having is regarding trying to persist a users search selection.

For example a user searches (for holidays) on the homepage. I would like the search box which is displayed on every page to hold the values of the previous search which are persisted in a session array.

I'm using the script from http://www.javascripttoolbox.com/lib/dynamicoptionlist/ to help me do the dependent select boxes and everything is working apart from when I try and use it to set the values of the search box at the bottom of the page if there has been a previous search.

Here's a snippet of code to help get across what I mean.

<?php
if( isset($_SESSION['previousUserSearch']['dynamic']) && !isset($_GET['load']) ){

	echo '<script>' . "\n";	
	
	//Below deals with persisting the year>month>day 
	echo 'document.getElementById("departure_year").value = "'.$_SESSION['previousUserSearch']['dynamic']['departureyear'].'";' . "\n";
	echo 'yearMonthDay.forField("departuremonth").setValues("'.$_SESSION['previousUserSearch']['dynamic']['departuremonth'].'");' . "\n";
	echo 'yearMonthDay.forField("departureday").setValues("'.$_SESSION['previousUserSearch']['dynamic']['departureday'].'");' . "\n";	
	
	
	echo 'alert(document.getElementById("departure_year").value);';
	
	
	//Deals with persisting the Country Resort	
	echo 'document.getElementById("to").value = "'.$_SESSION['previousUserSearch']['dynamic']['country'].'";' . "\n";
	echo 'countryResort.forField("resorts").setValues("'.$_SESSION['previousUserSearch']['dynamic']['resorts'].'");' . "\n";
	
	//deals with persisting the rooms required
	echo 'document.getElementById("rooms").value = "'.$_SESSION['previousUserSearch']['dynamic']['rooms'].'";' . "\n";
	
	//deals wiith persisting the duration
	echo 'document.getElementById("duration").value = "'.$_SESSION['previousUserSearch']['dynamic']['duration'].'";' . "\n";
	
	//deals with persisting the party info
	echo 'document.getElementById("adults").value = "'.$_SESSION['previousUserSearch']['dynamic']['adults'].'";' . "\n";
	echo 'document.getElementById("children").value = "'.$_SESSION['previousUserSearch']['dynamic']['children'].'";' . "\n";
	echo 'addChildrenAgesDynamic();';
	if( $_SESSION['previousUserSearch']['dynamic']['children'] != 0 ){
		$i = 1;
		while( $i <= $_SESSION['previousUserSearch']['dynamic']['children'] ){
			echo 'document.getElementById("childAge_'.$i.'").value = "'.$_SESSION['previousUserSearch']['dynamic']['childAge_'.$i.''].'";' . "\n";
			$i++;
		}
	}
	echo 'document.getElementById("infants").value = "'.$_SESSION['previousUserSearch']['dynamic']['infants'].'";' . "\n";
	
	//deals with persisting the accommodation options
	echo 'document.getElementById("board_basis").value = "'.$_SESSION['previousUserSearch']['dynamic']['board_basis'].'";' . "\n";
	echo 'document.getElementById("hotel_rating").value = "'.$_SESSION['previousUserSearch']['dynamic']['hotel_rating'].'";' . "\n";
	

	echo '</script>' . "\n";

}

This works in IE and FF but not in Safari and Chrome or I assume any webkit based browser.

Can anyone offer any help on this. I've tried researching and playing about with various things but nothing works.

I can say this if I alert() out the departure year after it's been set it does come up as 2010 (or whatever) but then after the page loads it is still set as 'year'


Thanks for any help in advance,

Richard