Jump to content

Odd $_GET issue driving me crazy!


iPixel

Recommended Posts

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!

 

Link to comment
Share on other sites

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'];

 

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.