...

View Full Version : Two steps forward one step back



h8ids
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);
to:
s.options[s.options.length] = new Option(emps[i][0],emps[i][1],false,false);


Here is the present source code.


<html>
<head>
<title>Add a course number for a faculty member</title>
</head>
<script type="text/javascript">
var gebi = function(elid){
//third activated alert INDICATES "Department";
alert(elid)
return document.getElementById(elid);
}
var emps = [
['Susie Dial','Moderator'],['Hugh Grant','Actor'],[]
];
//first activated alert SHOWS pairing of arrays "[Instructor,Department]"
alert(emps)
function updateDisplay(){
var i = this.value;
//second activated alert SHOWS array value of related Department, post the Instructor choice
alert(i)
gebi('Department').firstChild.nodeValue = (i>-1)?emps[i][1]:'';
//fourth activated alert RE-STATES array value of related department post display of department name
alert(i)
}
function init(){
var s = document.forms['empviewer'].elements['FacultyName'];
// second, when activated, alert STATES "[object HTMLSelectElement]"
//alert(s)
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;
</script>
<!-- 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'>
<option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&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>
</body>
</html>

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


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

h8ids
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum