View Full Version : Two steps forward one step back

01-24-2006, 08:29 PM
The assistance from this Forum has been invaluable! Thank you.

Now I have yet another question.
The original goal involved having PHP write JS and while doing so provide related data from two DB fields. (Using one DB.)
The webpage has a drop down which populates with the first field of data; "Names".
Once the user selects a name, the second field data comes into play; the related "Department" is automatically presented in the webpage for the user.

The forum helped to achieve the goal.

Now what I'm trying to do is pass the the selected name and related department back to the DB. But I was ran into a new problem, the department titles were storing in the DB as numbers (The numbers corresponded with their position in the generated array.)

I now have it to the point where the department title is passed to the database, BUT the web-page isn't automatically showing the department title.
I have set up alerts throughout the code to learn what the code is seeing.

The following is the only change made which caused the hiccup:

s.options[s.options.length] = new Option(emps[i][0],i,false,false);
s.options[s.options.length] = new Option(emps[i][0],emps[i][1],false,false);

Here is the present source code.

<title>Add a course number for a faculty member</title>
<script type="text/javascript">
var gebi = function(elid){
//third activated alert INDICATES "Department";
return document.getElementById(elid);
var emps = [
['Susie Dial','Moderator'],['Hugh Grant','Actor'],[]
//first activated alert SHOWS pairing of arrays "[Instructor,Department]"
function updateDisplay(){
var i = this.value;
//second activated alert SHOWS array value of related Department, post the Instructor choice
gebi('Department').firstChild.nodeValue = (i>-1)?emps[i][1]:'';
//fourth activated alert RE-STATES array value of related department post display of department name
function init(){
var s = document.forms['empviewer'].elements['FacultyName'];
// second, when activated, alert STATES "[object HTMLSelectElement]"
for (var i = 0;i<emps.length-1;i++){
s.options[s.options.length] = new Option(emps[i][0],emps[i][1],false,false);
s.onchange = updateDisplay;
window.onload = init;
<!-- Professor selection drop down box -->
<div style="position: absolute; width: 550px; left: 235px; top: 90px; z-index:5">
<select name="FacultyName" style='background-color: lightyellow'>
&nbsp;&nbsp;-- Select a professor --</option></select></div>
<div style="position: absolute; width: 550px; left: 235px; top: 120px; z-index:5">
<font color="#FFFFFF"><b><label>Department:&nbsp;</label></b><span id="Department">&nbsp;</span></div>

01-25-2006, 01:28 PM
did u try this

function updateDisplay(){
var i = this.value;
gebi('Department').firstChild.nodeValue = i ?i:'';

01-25-2006, 03:36 PM
That did solve the problem for FireFox but IE isn't recognizing the update.

I'll research the code to figure out how you came to the solution. I was thinking "var emps" would be necessary since it contained all names and departments.