Dynamic select boxes not setting values on page load in safari

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Mar 2008
Posts: 78
Reputation: rickya100 is an unknown quantity at this point 
Solved Threads: 1
rickya100 rickya100 is offline Offline
Junior Poster in Training

Dynamic select boxes not setting values on page load in safari

 
0
  #1
Oct 23rd, 2009
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.

  1.  
  2. <?php
  3. if( isset($_SESSION['previousUserSearch']['dynamic']) && !isset($_GET['load']) ){
  4.  
  5. echo '<script>' . "\n";
  6.  
  7. //Below deals with persisting the year>month>day
  8. echo 'document.getElementById("departure_year").value = "'.$_SESSION['previousUserSearch']['dynamic']['departureyear'].'";' . "\n";
  9. echo 'yearMonthDay.forField("departuremonth").setValues("'.$_SESSION['previousUserSearch']['dynamic']['departuremonth'].'");' . "\n";
  10. echo 'yearMonthDay.forField("departureday").setValues("'.$_SESSION['previousUserSearch']['dynamic']['departureday'].'");' . "\n";
  11.  
  12.  
  13. echo 'alert(document.getElementById("departure_year").value);';
  14.  
  15.  
  16. //Deals with persisting the Country Resort
  17. echo 'document.getElementById("to").value = "'.$_SESSION['previousUserSearch']['dynamic']['country'].'";' . "\n";
  18. echo 'countryResort.forField("resorts").setValues("'.$_SESSION['previousUserSearch']['dynamic']['resorts'].'");' . "\n";
  19.  
  20. //deals with persisting the rooms required
  21. echo 'document.getElementById("rooms").value = "'.$_SESSION['previousUserSearch']['dynamic']['rooms'].'";' . "\n";
  22.  
  23. //deals wiith persisting the duration
  24. echo 'document.getElementById("duration").value = "'.$_SESSION['previousUserSearch']['dynamic']['duration'].'";' . "\n";
  25.  
  26. //deals with persisting the party info
  27. echo 'document.getElementById("adults").value = "'.$_SESSION['previousUserSearch']['dynamic']['adults'].'";' . "\n";
  28. echo 'document.getElementById("children").value = "'.$_SESSION['previousUserSearch']['dynamic']['children'].'";' . "\n";
  29. echo 'addChildrenAgesDynamic();';
  30. if( $_SESSION['previousUserSearch']['dynamic']['children'] != 0 ){
  31. $i = 1;
  32. while( $i <= $_SESSION['previousUserSearch']['dynamic']['children'] ){
  33. echo 'document.getElementById("childAge_'.$i.'").value = "'.$_SESSION['previousUserSearch']['dynamic']['childAge_'.$i.''].'";' . "\n";
  34. $i++;
  35. }
  36. }
  37. echo 'document.getElementById("infants").value = "'.$_SESSION['previousUserSearch']['dynamic']['infants'].'";' . "\n";
  38.  
  39. //deals with persisting the accommodation options
  40. echo 'document.getElementById("board_basis").value = "'.$_SESSION['previousUserSearch']['dynamic']['board_basis'].'";' . "\n";
  41. echo 'document.getElementById("hotel_rating").value = "'.$_SESSION['previousUserSearch']['dynamic']['hotel_rating'].'";' . "\n";
  42.  
  43.  
  44. echo '</script>' . "\n";
  45.  
  46. }

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
Reply With Quote Quick reply to this message  
Reply

Tags
box, dependent, javascript, select

Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC