...

View Full Version : Help with listbox onchange event



SDonovan
12-01-2008, 04:57 PM
I have three values in this table tl_academic_year as Academic_Year.

0708
0809
0910

They stand for academic years for the university I work at.

I have the current academic year loaded in this table tl_config, as Academic_Year as well.

I need a way to look at grades, and or anything else for that matter by a listbox and an onchange event to query by year.

Here is an example:

I first get the course number and then see if an onchange event has occurred. If not I get the current year loaded in the tl_config table and then pull all my data for that course.


$Course_Number = $_GET['Course_Number'];

if(isset($_POST["year_list"])) {
$query_Year = $_POST['year_list'];
}else{
//Get the default academic year
$tl_config = $db->sql_fetchrow($db->sql_query("SELECT * FROM `".$prefix."_tl_config`"));
$query_Year = $tl_config['Academic_Year'];
}

$sessionresult = $db->sql_query("SELECT * FROM ".$prefix."_tl_session WHERE Course_Number = '$Course_Number' AND Academic_Year = '$query_Year' ORDER BY TLDate");


My form looks like so:


OpenTable();
echo "<form name=\"sessionList\" action='".$_server['php_self']."' method='post'>";
echo "<table width='100%' border='1' cellspacing='0' cellpadding='2'>\n";
echo "<tr><td colspan='3' width='100%' bgcolor='$bgcolor2'><nobr>TL Session Options for $Course_Name</nobr></td>";
//Need a way to get all academic years so I can view any records
$getYear = $db->sql_query("SELECT Academic_Year FROM atlas_tl_academic_year ORDER BY Academic_Year");
echo"<td> <SELECT name=\"year_list\ onchange=\"document.getElementById('sessionList').submit();\">";
while($row = $db->sql_fetchrow($getYear)) {
echo '<option value="'.$row["Academic_Year"].'"';
if($row["Academic_Year"] == $query_Year) {
echo ' selected';
}
echo '>'.$row["Academic_Year"].'</option>';
}
echo '</select>';
echo"</td></tr>\n";
echo "</form>";

Nothing happens. The form does not refresh. I have tried this as well but nothing so far.


onchange=\"this.sessionList.submit();\"

SDonovan
12-01-2008, 05:09 PM
I did this ...


if(isset($_POST["year_list"])) {
$query_Year = $_POST['year_list'];
OpenTable();
echo "$query_Year";
CloseTable();
die();
}else{
//Get the default academic year
$tl_config = $db->sql_fetchrow($db->sql_query("SELECT * FROM `".$prefix."_tl_config`"));
$query_Year = $tl_config['Academic_Year'];
}

and can see the correct value from the $query_Year and the page died so it is getting refreshed but I am not seeing any values for 0809. I have 5 records with Academic_Year = 0809 in my session table.

This query should pull those records if $query_Year has the correct value.


SELECT * FROM ".$prefix."_tl_session WHERE Course_Number = '543' AND Academic_Year = '0809' ORDER BY TLDate

I can't see where or if it is getting stepped on.

abduraooft
12-01-2008, 05:10 PM
Can we have a link to your page? There might be some errors in your html output. (Always validate your code)

ohgod
12-01-2008, 05:16 PM
something quick to try, change

document.getElementById('sessionList').submit();
to

document.sessionList.submit();

also, be careful of using single quotes inside double quotes. you can use doubles inside of singles, but not the other way around (without escaping them, of course)


as for the query itself, if you have error reporting turned on it should say if it doesn't like the query. but to be sure, try running the query directly in smoething like phpmyadmin. it could give clues.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum