h8ids
10-12-2006, 04:04 PM
Pulling data into a listbox.
The data keeps showing up "reversed"; the last record is showing up as the first option. But this only occurs in Firefox, IE works fine.
There is a reference to an external JS function (onclick="activeMajorRev()"), but it only activates a button.
The code has some JS mixed in to assist with user selection.
HTML first:
<form name="f1">
<div id="MajorEdit" name="MajorEdit" style='display: none'>
<b>Edit</b> a Major.
<input type="text" name="MajorEdit" id="MajorEdit" size="4" onclick="activeMajorRev()">
<input type="text" name="MajorEdit2" size="35" onclick="activeMajorRev()">
<input type="text" name="MajorEdit3" size="3"><br>
<input disabled type="submit" value="Save revisions" name="MajorRev" id="MajorRev" title="Store Major revisions" onclick="this.form.action='DBEditMajor.php'; resolveData();">
<p></div>
</form>
php with JS:
<script type="text/javascript">
var empMajorChoice = [
<?php //error_reporting(E_ALL);
$dbMajor = mysql_connect("localhost", "root", "");
mysql_select_db("newcourse",$dbMajor);
$resultMajor = mysql_query('SELECT Majors,MajorCode,Records FROM majors');
$count = 1;
$num = mysql_num_rows($resultMajor);
if ($num != 0) {
while ($rowMajor = mysql_fetch_array($resultMajor)) {
echo "['$rowMajor[0]','$rowMajor[1]','$rowMajor[2]']";
if($count < $num){
echo ",";
}
$count++;
}
}
mysql_free_result($resultMajor);
?>
];
//Collecting of paired data for Major presentation
for(var a=0;a<empMajorChoice.length;a++){
document.f1.MajorChoice[document.f1.MajorChoice.length] = new Option(empMajorChoice[a][0],empMajorChoice[a][1],empMajorChoice[a][2])
}
// Populating Major Edit fields
function testMajor(objMajor){
if(objMajor.selectedIndex!=0){
document.f1.MajorEdit.value=empMajorChoice[objMajor.selectedIndex][1]
document.f1.MajorEdit2.value=empMajorChoice[objMajor.selectedIndex][0]
document.f1.MajorEdit3.value=empMajorChoice[objMajor.selectedIndex][2]
} else {
document.f1.MajorEdit.value="";
document.f1.MajorEdit2.value="";
document.f1.MajorEdit3.value="";
}
}
</script>
The data keeps showing up "reversed"; the last record is showing up as the first option. But this only occurs in Firefox, IE works fine.
There is a reference to an external JS function (onclick="activeMajorRev()"), but it only activates a button.
The code has some JS mixed in to assist with user selection.
HTML first:
<form name="f1">
<div id="MajorEdit" name="MajorEdit" style='display: none'>
<b>Edit</b> a Major.
<input type="text" name="MajorEdit" id="MajorEdit" size="4" onclick="activeMajorRev()">
<input type="text" name="MajorEdit2" size="35" onclick="activeMajorRev()">
<input type="text" name="MajorEdit3" size="3"><br>
<input disabled type="submit" value="Save revisions" name="MajorRev" id="MajorRev" title="Store Major revisions" onclick="this.form.action='DBEditMajor.php'; resolveData();">
<p></div>
</form>
php with JS:
<script type="text/javascript">
var empMajorChoice = [
<?php //error_reporting(E_ALL);
$dbMajor = mysql_connect("localhost", "root", "");
mysql_select_db("newcourse",$dbMajor);
$resultMajor = mysql_query('SELECT Majors,MajorCode,Records FROM majors');
$count = 1;
$num = mysql_num_rows($resultMajor);
if ($num != 0) {
while ($rowMajor = mysql_fetch_array($resultMajor)) {
echo "['$rowMajor[0]','$rowMajor[1]','$rowMajor[2]']";
if($count < $num){
echo ",";
}
$count++;
}
}
mysql_free_result($resultMajor);
?>
];
//Collecting of paired data for Major presentation
for(var a=0;a<empMajorChoice.length;a++){
document.f1.MajorChoice[document.f1.MajorChoice.length] = new Option(empMajorChoice[a][0],empMajorChoice[a][1],empMajorChoice[a][2])
}
// Populating Major Edit fields
function testMajor(objMajor){
if(objMajor.selectedIndex!=0){
document.f1.MajorEdit.value=empMajorChoice[objMajor.selectedIndex][1]
document.f1.MajorEdit2.value=empMajorChoice[objMajor.selectedIndex][0]
document.f1.MajorEdit3.value=empMajorChoice[objMajor.selectedIndex][2]
} else {
document.f1.MajorEdit.value="";
document.f1.MajorEdit2.value="";
document.f1.MajorEdit3.value="";
}
}
</script>