Forum Moderators: open

Message Too Old, No Replies

Not Filling Second Drop Down

         

xtremer360

8:19 pm on Dec 3, 2009 (gmt 0)

10+ Year Member



I'm having one more problem with my ajax and need some assistance on if someone can lend a hand.

I know this is probably going to be obvious when I get told what I'm doing wrong but here it goes anyway.

Why isn't it the drop down arenas list filling with corresponding names of the arenas when a country is chosen? As of right now nothing fills in it.

arenas.php


print '<tr>';
print '<td class="rowheading">Country</td>';
print '<td class="row3" colspan="2"><select name="countryid" class="dropdown" onchange="ajaxpage("backstageajax.php?random=625094862&routine=arenas&countryid="+showbooker.countryid.value,"arenaajax");"><option value=0>- Select -</option>';
$query = 'SELECT * FROM efed_list_arenas_countries ORDER BY `country`';
$result = mysql_query ( $query );
while ( $row = mysql_fetch_assoc ( $result ) )
{
print "<option value=\"".$row['country']."\">".$row['country']."</option>\r";
}
print '</select></td>';
print '</tr>';
print '<tr>';
print '<td class="rowheading">Arena</td>';
print '<td class="row3" colspan="2"><div id="arenaajax"><select name="arenaid" class="dropdown"><option value="0">- Select Arena -</select><input type="hidden" name="location" value="0"></div></td>';
print '</tr>';

ajax.php


<?php
if (isset($_GET['countryid'])) {$countryid=$_GET{'countryid'};}

case "arenas":
print "<select name=arenaid class=dropdown><option value=0>- Select -";
$query = "SELECT
ela.id as getarenaid,
ela.city as getarenacity,
ela.arena as getarenaname,
ela.capacity as getcapacity
FROM
efed_list_arenas as ela
WHERE
ela.country_id = '$countryid'
ORDER BY
ela.arena";
$result = mysql_query ($query);
while ($row = mysql_fetch_assoc($result))
{
$fieldarray=array('getarenaid','getarenacity','getarenaname','getcapacity');
foreach ($fieldarray as $fieldlabel)
{
if (isset($row[$fieldlabel]))
{
$$fieldlabel=$row[$fieldlabel];
$$fieldlabel=htmlentities($$fieldlabel);
}
}

print "<option value=\"".$getarenaid."\">".$getarenaname." - ".$getarenacity;
}
print "</select>\n";

break;

?>

Fotiman

9:22 pm on Dec 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I don't have time to look in depth, but I notice immediately that you have some issues with quotes that could be causing problems.

For example:
onchange="ajaxpage("backstageajax.php?...

The browser is going to see that as:

onchange="ajaxpage("

I would start there, fix your quotes, and that might solve your problem.

xtremer360

9:28 pm on Dec 3, 2009 (gmt 0)

10+ Year Member



So it's supposed to be single quote for the thing between the parenthesis?

rocknbil

10:12 pm on Dec 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you look at the Error Control Panel in FireFox (which you should) you probably have an error. The problem is not that "it's supposed to be single quotes" it's in how it's nested in the onchange. You have to swap or escape nested quotes.

onchange="ajaxpage('backstageajax.php?random=625094862&routine=arenas&countryid='+showbooker.countryid.value,'arenaajax');">

or

onchange='ajaxpage("backstageajax.php?random=625094862&routine=arenas&countryid="+showbooker.countryid.value,"arenaajax");'>

A second problem here is good error checking. Verify the value is what you expect. You are probably passing a blank value to $countryid, and since it's quoted it won't give a mysql error, it will just look for entries "where country_id='' which there probably are none.

I am guessing by the first query it's not really a numeric ID, it's a country code, so going on that assumption,


if (
isset($_GET['countryid']) and
preg_match('/^\w{2}$/i',$_GET['countryid'])
) {$countryid=$_GET['countryid']; }
else {
echo "OOPS country id is not valid input: " . $_GET['countryid'];
exit;
}

PHP bugs me in that $_GET{'countryid'} and $_GET['countryid'] are synonymous for associative arrays, in other languages [] refers only to an index, {} is an association . . . no matter here, I think . . .

The previous will "trap" the problem for you, leading to the cause and a solution, but it also validates the input - assuming, of course, it's only a two letter country code. If it's numeric,


if (
isset($_GET['countryid']) and
preg_match('/^\d+$/i',$_GET['countryid'])
) {$countryid=$_GET['countryid']; }
else {
echo "OOPS country id is not valid input: " . $_GET['countryid'];
exit;
}