setting the input text w/ AJAX

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shaunwo
    New Member
    • Feb 2008
    • 1

    setting the input text w/ AJAX

    I'm an AJAX / DOM Novice (at best) and trying to figure out how to write the value to a couple input fields. I don't remember exactly where I got the ajax.js file I'm using from (went to the website that I see in the comments, but no luck there), but what I already have works GREAT to populate the options in a select box. Now I'm trying to take that same code and get it to write the value to a couple input boxes.

    Here's a link to my ajax javascript file:
    http://www.leadingedge roofing.com/manage/j/ajax.js

    On the file that IS WORKING (get_material_c ontainers.php) and writing the option tags, my code looks like this:

    Code:
    $container_r = @mysql_query($container_q) OR die ($container_q.'<br /><br />'.mysql_error());
    if (mysql_num_rows($container_r) > 0) {
    	echo 'obj.options[obj.options.length] = new Option(\' - select - \',\'\');'."\n";
    	while ($container = mysql_fetch_array($container_r)) {
    		echo 'obj.options[obj.options.length] = new Option(\''.addslashes(htmlentities($container['material_container'])).'\');'."\n";
    	}
    } else {
    	echo 'obj.options[obj.options.length] = new Option(\' - select - \',\'\');'."\n";
    }
    And then here's what's NOT working to try and write to the text fields, from the get_manufacture r_warranty.php file:

    Code:
    if (mysql_num_rows($warranty_r) > 0) {
    	echo 'obj.input = \''.mysql_result($warranty_r,0,'manf_warranty_cost').'\'; // set the value for the hidden input box
    obj2.input = \''.mysql_result($warranty_r,0,'manf_warranty_cost').'\'; // set the value for the disabled input box';
    }
    And lastly, here's the code I have to call each file:

    Code:
    var ajax = new Array();
    
    function getContainerList(materialSel,materialType,containerSel) {
    	var material = materialSel.options[materialSel.selectedIndex].value;
    	document.getElementById(containerSel).options.length = 0; // Empty the select box
    	if(material.length>0){
    		var index = ajax.length;
    		ajax[index] = new sack();
    		
    		ajax[index].requestFile = 'http://www.leadingedgeroofing.com/manage/inc/get_material_containers.php?material_type='+materialType+'&manf_id='+material;	// Specifying which file to get
    		ajax[index].onCompletion = function(){ createContainers(index,containerSel) };	// Specify function that will be executed after file has been found
    		ajax[index].runAJAX();		// Execute AJAX function
    	}
    }
    
    function createContainers(index,containerSel) {
    	var obj = document.getElementById(containerSel);
    	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
    }
    
    function getWarrantyCost(materialSel,warrantyCost) {
    	var material = materialSel.options[materialSel.selectedIndex].value;
    	document.getElementById(warrantyCost).value = ''; // Empty the hidden input box
    	document.getElementById(warrantyCost + '-disabled').value = ''; // Empty the 'disabled' input box
    	if(material.length>0){
    		var index = ajax.length;
    		ajax[index] = new sack();
    		
    		ajax[index].requestFile = 'http://www.leadingedgeroofing.com/manage/inc/get_manufacterer_warranty.php?manf_id='+material;	// Specifying which file to get
    		ajax[index].onCompletion = function(){ createWarrantyCost(index,warrantyCost) };	// Specify function that will be executed after file has been found
    		ajax[index].runAJAX();		// Execute AJAX function
    	}
    }
    
    function createWarrantyCost(index,warrantyCost) {
    	var obj = document.getElementById(warrantyCost);
    	var obj2 = document.getElementById(warrantyCost + '-disabled');
    	eval(ajax[index].response); // Executing the response from Ajax as Javascript code
    }
    I'm hoping someone who's more familiar w/ DOM and AJAX will be able to see what I'm doing wrong fairly easily and be able to give me some pointers.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Originally posted by shaunwo
    And then here's what's NOT working to try and write to the text fields, from the get_manufacture r_warranty.php file:

    Code:
    if (mysql_num_rows($warranty_r) > 0) {
    	echo 'obj.input = \''.mysql_result($warranty_r,0,'manf_warranty_cost').'\'; // set the value for the hidden input box
    obj2.input = \''.mysql_result($warranty_r,0,'manf_warranty_cost').'\'; // set the value for the disabled input box';
    }
    'obj.input' should be 'obj.value'.

    Comment

    Working...