Web Analytics Made Easy -
StatCounter Populating an <INPUT> area dynamically - CodingForum


No announcement yet.

Populating an <INPUT> area dynamically

  • Filter
  • Time
  • Show
Clear All
new posts

  • Populating an <INPUT> area dynamically

    I have a listbox which presents data by means of PHP.
    The PHP code also draws data from related record fields.

    Once the PHP is done the following source code becomes available:
    var emps = [
    ['American Studies','AMST'],['Anglican Studies','ANGL'],['Anthropology','ANTH']
    These, ( Please Choose One, American Studies, Anglican Studies...),
    appear as options in a listbox. Based upon the user's choice, the tied data should appear in a <input> box for editting.
    This is where the problem comes into play. Running into a problem with the related data appearing in an <INPUT> box.

    Page Source code:
    	<script type="text/javascript">
    		var gebi = function(ELID){
    			return document.getElementById(ELID);	}
    		var emps = [
    		['American Studies','AMST'],['Anglican Studies','ANGL'],['Anthropology','ANTH']
    		function updateDisplay(){
    			var i = parseInt(this.value);
    			gebi('deptspan').firstChild.nodeValue = (i>-1)?emps[i][1]:'';	}
    		function init(){
    			var s = document.forms['empviewer'].elements['emplist'];
    			for (var i = 0; i < emps.length-1; i++){
    				s.options[s.options.length] = new Option(emps[i][0],i);	}
    			s.onchange = updateDisplay;	}
    		window.onload = init;
    <body topmargin="0" marginheight="0">
    <FORM name="empviewer">
    <div id="emptitle" style="position: absolute; width: 550px; left: 235px; top: 90px; z-index:5">
    <tr bgcolor='#E0E0E0'>
    	<td><select name="emplist" style='background-color: lightyellow'>
    <option value="-1">Select a Dept </option>
    <span id="deptspan">&nbsp;</span>
    Last edited by h8ids; Sep 28, 2006, 05:40 PM.