When you generate the JavaScript function (abc) with PHP, it will always do the same thing - as the output of it never changes once the page has loaded. Therefore - if you want something to happen after the page has loaded - you must write a function in JavaScript that tests the Lab_credit_hr. To get the Lab_credit_hr’s into JavaScript, you could output JavaScript code which can then be used by your function:
You are also echoing out the value of $option2 before the closing tag.
[php] [/php]
Becomes:
[php]<?php
include_once('connect.php');
$courses = mysql_query("SELECT `Lab_credit_hr` FROM `courses`;");
if(mysql_num_rows($courses) >= 1) {
ob_start();
echo 'var courses = Array();';
while($row = mysql_fetch_array($courses)) {
echo "courses['", $courses['Course_Number'], "'] = '", $row['Lab_credit_hr']. "';";
}
$js = ob_get_contents();
ob_end_clean();
}
?>
[/php]