iPixel Posted December 8, 2009 Share Posted December 8, 2009 So i have a form with dropdowns. All dropdowns are static with the exception of one dropdown which changes via AJAX depending on what the previous dropdown has selected. So... once the first dropdown is selected, it passes a "branch id" through ajax to a page that does this. <?php // THIS PAGE DOES THE DYNAMIC DEPARTMENT DROPDOWN include('c2db.php'); //get the q parameter from URL $q = mysql_real_escape_string($_GET["q"]); $SP_query = "SELECT * FROM xr_dept WHERE BranchID = '$q'"; $SP_sql = mysql_query($SP_query) or die(mysql_error()); $display_string = "<select name='form_department' id='form_department' class='login_txt_box'>"; while($SP_result = mysql_fetch_assoc($SP_sql)) { $display_string .= "<option value='" . $SP_result['DeptID'] . "'>" . $SP_result['DeptName'] . "</option>"; } $display_string .= "</select>"; echo $display_string; ?> So based on the branch selected, department names are selected from the database. And the string to echo the entire select form field is echoed. This part works just fine as intended. The issue is, when i post using "get" method... the form_department does not get passed and i just cant see why. Could the way i generate the drop down field have something to do with this? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/184418-odd-_get-issue-driving-me-crazy/ Share on other sites More sharing options...
rajivgonsalves Posted December 8, 2009 Share Posted December 8, 2009 Your code looks fine you might want to check that your branch id is getting passed rightly in your ajax code. Quote Link to comment https://forums.phpfreaks.com/topic/184418-odd-_get-issue-driving-me-crazy/#findComment-973498 Share on other sites More sharing options...
iPixel Posted December 8, 2009 Author Share Posted December 8, 2009 It is getting passed properly, because the drop downs get generated correctly based on the passed branch id's Quote Link to comment https://forums.phpfreaks.com/topic/184418-odd-_get-issue-driving-me-crazy/#findComment-973501 Share on other sites More sharing options...
mrMarcus Posted December 8, 2009 Share Posted December 8, 2009 do the <option> values contain the correct value? how are you grabbing the 'form_department' on the other end? Quote Link to comment https://forums.phpfreaks.com/topic/184418-odd-_get-issue-driving-me-crazy/#findComment-973505 Share on other sites More sharing options...
iPixel Posted December 8, 2009 Author Share Posted December 8, 2009 Here's the whole 9 yards of code so you have everything you need to gimmie your best guesstimates. Start like so... <select name="form_branch" id="form_branch" class="form_dropdown" onChange="ajaxFunctionDDD(this.value)"> <option value="0">SELECT A BRANCH</option> <?php $branch_query = "SELECT * FROM xr_branch"; $branch_sql = mysql_query($branch_query) or die(mysql_error()); $branch_res = mysql_fetch_assoc($branch_sql); do { ?> <option value="<?php echo $branch_res['BranchID']; ?>"><?php echo $branch_res['BranchName']; ?></option> <?php } while($branch_res = mysql_fetch_assoc($branch_sql)); ?> </select> ---- Notice the "onChange="ajaxFunctionDDD(this.value)"" this calls the ajax which looks like so.. // AJAX for dropdown creation on Add employee Form function ajaxFunctionDDD(q) { // alert(q); var ajaxRequest; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function() { if(ajaxRequest.readyState == 4) { var ajaxDisplay = document.getElementById('TheDropdownTD'); ajaxDisplay.innerHTML = ajaxRequest.responseText; } } ajaxRequest.open("GET", "../DepDropDown.php?q=" + q, true); ajaxRequest.send(null); } ----- The ajax as you see calls DepDropDown.php using the GET method and passing the q variable DepDropDown.php <?php // THIS PAGE DOES THE DYNAMIC DEPARTMENT DROPDOWN FOR ADD EMPLOYEE \\ include('c2db.php'); //get the q parameter from URL $q = mysql_real_escape_string($_GET["q"]); $SP_query = "SELECT * FROM xr_dept WHERE BranchID = '$q'"; $SP_sql = mysql_query($SP_query) or die(mysql_error()); $display_string = "<select name='form_department' id='form_department' class='login_txt_box'>"; while($SP_result = mysql_fetch_assoc($SP_sql)) { $display_string .= "<option value='" . $SP_result['DeptID'] . "'>" . $SP_result['DeptName'] . "</option>"; } $display_string .= "</select>"; echo $display_string; ?> ----- If you refer back to the AJAX portion this looks for an ID to fill in which get's done here... <td style="border-bottom:1px solid #e7e7e7;" id="TheDropdownTD"> <select name="form_department" id="form_department" class="login_txt_box" > </select> </td> ----- after submit... that page simply echoes all fields passed, and form_department is not working echo $_GET['form_department']; Quote Link to comment https://forums.phpfreaks.com/topic/184418-odd-_get-issue-driving-me-crazy/#findComment-973513 Share on other sites More sharing options...
iPixel Posted December 8, 2009 Author Share Posted December 8, 2009 WOW you wont believe it !!!! The code is 100% fine LOL!!!! I recently started using Google Chrome alot, cause it's neat and clean and stuff. Aparently google chrome does not like ajax i guess or something, because out of sheer hopelessness i decided to run that page off IE and it works fine with no issues whatsoever. After restarting chrome i tried once more and nothing! So i'm just going to blame google for this one. FF doesnt work either Thanks All who tried to help! Quote Link to comment https://forums.phpfreaks.com/topic/184418-odd-_get-issue-driving-me-crazy/#findComment-973631 Share on other sites More sharing options...
mrMarcus Posted December 8, 2009 Share Posted December 8, 2009 Aparently google chrome does not like ajax i guess or something So i'm just going to blame google for this one. there's obviously a more rational explanation than Google just "not liking" AJAX, seeing as how the majority of their web technologies are built on, and rely heavily on AJAX/javascript. try clearing your cache in Chrome. AJAX has a tenancy to give misleading results if you don't handle the cache accordingly, which i'm assuming you're not. try clearing your cache. then try again. Quote Link to comment https://forums.phpfreaks.com/topic/184418-odd-_get-issue-driving-me-crazy/#findComment-973634 Share on other sites More sharing options...
iPixel Posted December 8, 2009 Author Share Posted December 8, 2009 I cleared my cache and nothing, still the same error. Yea i'm sure it's not like it's googles fault lol, but what other explanation can there be. Quote Link to comment https://forums.phpfreaks.com/topic/184418-odd-_get-issue-driving-me-crazy/#findComment-973642 Share on other sites More sharing options...
mrMarcus Posted December 8, 2009 Share Posted December 8, 2009 you sure you cleared the cache completely? try accessing the page manually by typing it into the address bar with the appropriate variables in the URL in Chrome. so: http://localhost/path/to/DepDropDown.php?q=put_string_here i find it hard to believe that Chrome would be the odd man out in this, and since you were doing all your testing within Chrome, it sounds like a cache issue since first tries within IE and FF were successful. aside from that, i got nothing else at the moment. Quote Link to comment https://forums.phpfreaks.com/topic/184418-odd-_get-issue-driving-me-crazy/#findComment-973647 Share on other sites More sharing options...
iPixel Posted December 8, 2009 Author Share Posted December 8, 2009 This also does not work in FireFox & Safari, i also added an alert(ajaxRequest.responseText); in the ajax script just to make sure it creates the dropdown as it's supposed to and it does. I did the http://localhost/path/to/DepDropDown.php?q=22 and it worked just fine. Yes I'm sure i cleared the cache compeltely. I even tried this on various PC's with same results. PS: quick noob question... if you change something on the client side with js / ajax will the source code when viewed be changed as well? so if you innerHTML a div will you see the newly inserted HTML within that div while viewing source code through broser? Quote Link to comment https://forums.phpfreaks.com/topic/184418-odd-_get-issue-driving-me-crazy/#findComment-973660 Share on other sites More sharing options...
mrMarcus Posted December 8, 2009 Share Posted December 8, 2009 so, typing this directly into the address bar in Chrome/Firefox works ok? http://localhost/path/to/DepDropDown.php?q=22 might be a path issue. change: ajaxRequest.open("GET", "../DepDropDown.php?q=" + q, true); to: ajaxRequest.open("GET", "http://localhost/path/to/DepDropDown.php?q=" + q, true); worth a shot, otherwise, consider moving this thread over to the javascript help form as this has become nothing of a PHP problem that i can see, and i'm sure the Javascript Gurus will be able to help you out 10x faster than I. Quote Link to comment https://forums.phpfreaks.com/topic/184418-odd-_get-issue-driving-me-crazy/#findComment-973685 Share on other sites More sharing options...
iPixel Posted December 8, 2009 Author Share Posted December 8, 2009 Still nothing. How can i move this to the JS forum? Do i just start a new topic there with a link to this thread? Quote Link to comment https://forums.phpfreaks.com/topic/184418-odd-_get-issue-driving-me-crazy/#findComment-973699 Share on other sites More sharing options...
premiso Posted December 8, 2009 Share Posted December 8, 2009 Do i just start a new topic there with a link to this thread? I would just start a new topic in the JS forum and post what the new problem / issue is with code examples and you can put as a reference a link to this topic. Quote Link to comment https://forums.phpfreaks.com/topic/184418-odd-_get-issue-driving-me-crazy/#findComment-973705 Share on other sites More sharing options...
iPixel Posted December 8, 2009 Author Share Posted December 8, 2009 OK, i just didnt want to spam but i'll do that! Thanks Guys! I'll check back here if i have a solution. Quote Link to comment https://forums.phpfreaks.com/topic/184418-odd-_get-issue-driving-me-crazy/#findComment-973715 Share on other sites More sharing options...
iPixel Posted December 9, 2009 Author Share Posted December 9, 2009 Finally figured out what was going on. For some reason the object / element whatever you wanna call it was missing from the html DOM after it was dynamically created. Anyways you can see the answer here in the AJAX forum. http://www.phpfreaks.com/forums/index.php/topic,279959.0.html Thanks guys! Quote Link to comment https://forums.phpfreaks.com/topic/184418-odd-_get-issue-driving-me-crazy/#findComment-974329 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.