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

Announcement

Collapse
No announcement yet.

Populating an <INPUT> area dynamically

Collapse
X
 
  • 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:
    Code:
    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:
    Code:
    <HTML><HEAD>
    	<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;
    
    	</script>
    </HEAD>
    <body topmargin="0" marginheight="0">
    <FORM name="empviewer">
    <div id="emptitle" style="position: absolute; width: 550px; left: 235px; top: 90px; z-index:5">
    <table>
    <tr bgcolor='#E0E0E0'>
    	<td><select name="emplist" style='background-color: lightyellow'>
    <option value="-1">Select a Dept </option>
    </select></td></tr>
    </table>
    </form>
    <label>&nbsp;MajorCode:&nbsp;</label>
    <span id="deptspan">&nbsp;</span>
    </div>
    </body>
    </html>
    Last edited by h8ids; Sep 28, 2006, 05:40 PM.
Working...
X