sKunKbad Posted May 24, 2009 Share Posted May 24, 2009 I've got a theme changer script, and it works good in any browser on Windows. I've tried Chrome, FF3, IE6, Opera, and Safari. When I go to my Mac, it works fine in Opera, but Safari and FF3 don't work, and on my Ubuntu laptop, using FF3, it doesn't work. The odd thing is, in all of these browsers, it works on the next page load. I thought maybe somebody in here would spot what was buggy. FORM: <form action="http://localhost/CodeIgniter/theme_choice.php" method="post"> <div id="themeBox"> <h3 style="margin-bottom:0px;"><label for="theme_choice">Pick a theme:</label></h3> <p style="font-size:80%; padding-top:0px; margin-top:0px;">current theme is "Blue Seashore"</p> <select id="theme_choice" name="theme_choice" onchange="goto_URL(this.form.theme_choice)" onkeyup="goto_URL(this.form.theme_choice)"> <option value="NA" selected="selected"> -- Select One --</option> <option value="blue_theme"> Blue Seashore </option> <option value="green_theme"> Green Army </option> <option value="mocha_theme"> Java Addiction </option> <option value="yellow_theme"> Ketchup & Mustard </option> <option value="dark_theme"> Midnight Mardi Gras </option> <option value="rose_theme"> Rose Garden </option> </select> </div> <noscript> <div id="themeButton"> <input type="hidden" name="referer" value="index.php" /> <input class="inputbutton" type="submit" value="Change Theme" /> </div> </noscript> </form> SCRIPT: function goto_URL(object) { if(object.options[object.selectedIndex].value != 'NA'){ var key = 'theme_choice='; var value = object.options[object.selectedIndex].value; var url = 'http://localhost/CodeIgniter/theme_choice.php'; var params = key + value; function createRequestObject() { var req; if(window.XMLHttpRequest){ req = new XMLHttpRequest(); } else if(window.ActiveXObject) { req = new ActiveXObject('Microsoft.XMLHTTP'); } else { alert('There was a problem creating the XMLHttpRequest object'); } return req; } var http = createRequestObject(); http.open('POST', url, true); http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); http.setRequestHeader('Content-length', params.length); http.setRequestHeader('Connection', 'close'); http.onreadystatechange = function(){ if(http.readyState == 4 && http.status == 200){ window.location.href = 'http://localhost/CodeIgniter/'; } } http.send(params); } } THEME_CHOICE.PHP: <?php class Theme_choice extends Controller { function Theme_choice(){ parent::Controller(); } public function index(){ if ($this->input->post('theme_choice')){ $theme_choice = filter_input(INPUT_POST, 'theme_choice' , FILTER_SANITIZE_STRING ); if($theme_choice != 'NA'){ $_SESSION['stylesheet'] = $theme_choice; } } if($this->input->post('referer') && $this->input->post('referer') != 'index.php'){ $samePage = base_url() . filter_input(INPUT_POST, 'referer' , FILTER_SANITIZE_URL ); header("Location: " . $samePage ); }else{ $samePage = base_url(); header("Location: " . $samePage ); } } } ?> Javascript is not my strength, so I'm hoping one of you Javascript gurus can teach me something here. Thanks. Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted May 24, 2009 Author Share Posted May 24, 2009 I figured out my own problem. It was with the theme_choice.php script. I'm just guessing, but other than trying to set the session variable, there was no output to "give back" to the javascript, and it may have been tripping up the javascript. I added a 200 OK header, and some text to the output, and all is well. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.