Reply
How can I mix some PHP code that uses MySQL variables with Javascript?
Old 10-12-2006, 04:02 PM How can I mix some PHP code that uses MySQL variables with Javascript?
Junior Talker

Posts: 1
Name: Denis Hoye
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!
denishoye is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Reply     « Reply to How can I mix some PHP code that uses MySQL variables with Javascript?
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Webmaster Resources Marketplace:
Software Development Company | Webhosting.UK.com | Text Link Brokers 


   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.10829 seconds with 12 queries