First, the following php code is found in a file called: profile.inc.
----------------------------------------------------------------------------
// now we display the form with all of the information stored in local variables
// if viewing, they will have data from database, otherwise they will be blank <select name="bldgid" id="bldgid" onchange="setTeam()"> $result = execSql("select bldgid, name from bldgs order by name");
while ( $row = mysql_fetch_array ( $result, MYSQL_ASSOC ) ) {
echo "<option value=\"{$row['bldgid']}\"";
if ( $bldgid==$row['bldgid'] ) echo " selected";
}
mysql_free_result($result); Second I have some Javascript code in a file called profile.php:
---------------------------------------------------------------------------
// generate a little javascript to assign buildings to teams
echo <<<JAVASCRIPT
<script language="javascript">
function setTeam() { idx = document.getElementById("bldgid").selectedIndex; bldgName = document.getElementById("bldgid").options[idx].text; if (bldgName == "Triumph Campus 1")
setTeamOption( "TR Team 1");
else if (bldgName == "Triumph Campus 2")
setTeamOption( "TR Team 2");
elseif (bldgName == "Triumph Campus 3")
setTeamOption( "TR Team 3");
else if (bldgName == "Triumph Campus 4")
setTeamOption( "TR Team 4");
}
function setTeamOption(teamName) { teamMenu = document.getElementById("teamid"); for (i = 0; i < teamMenu.options.length; i++)
{ if (teamMenu.options[i].text == teamName)
{ teamMenu.options[i].selected = true;
break; }
} }
</script>
JAVASCRIPT;
-------------------------
This works to set the team automatically when I select the building, but relies on hard coding. What I would like to know is how I can replace the code: (bldgName == "Triumph Campus 1")
setTeamOption( "TR Team 1");
with php variables that will allow me to make this selection dynamic.
Thanks!
|