Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jan 2006
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Two steps forward one step back

    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:
    Code:
    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.
    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>

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    did u try this
    Code:
    function updateDisplay(){
    var i = this.value;
    gebi('Department').firstChild.nodeValue = i ?i:'';
    }

  • #3
    Regular Coder
    Join Date
    Jan 2006
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    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.
    Last edited by h8ids; 01-25-2006 at 02:50 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •