472,142 Members | 1,210 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,142 software developers and data experts.

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.leadingedgeroofing.com/manage/j/ajax.js

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

Expand|Select|Wrap|Line Numbers
  1. $container_r = @mysql_query($container_q) OR die ($container_q.'<br /><br />'.mysql_error());
  2. if (mysql_num_rows($container_r) > 0) {
  3.     echo 'obj.options[obj.options.length] = new Option(\' - select - \',\'\');'."\n";
  4.     while ($container = mysql_fetch_array($container_r)) {
  5.         echo 'obj.options[obj.options.length] = new Option(\''.addslashes(htmlentities($container['material_container'])).'\');'."\n";
  6.     }
  7. } else {
  8.     echo 'obj.options[obj.options.length] = new Option(\' - select - \',\'\');'."\n";
  9. }
  10.  
And then here's what's NOT working to try and write to the text fields, from the get_manufacturer_warranty.php file:

Expand|Select|Wrap|Line Numbers
  1. if (mysql_num_rows($warranty_r) > 0) {
  2.     echo 'obj.input = \''.mysql_result($warranty_r,0,'manf_warranty_cost').'\'; // set the value for the hidden input box
  3. obj2.input = \''.mysql_result($warranty_r,0,'manf_warranty_cost').'\'; // set the value for the disabled input box';
  4. }
  5.  
And lastly, here's the code I have to call each file:

Expand|Select|Wrap|Line Numbers
  1. var ajax = new Array();
  2.  
  3. function getContainerList(materialSel,materialType,containerSel) {
  4.     var material = materialSel.options[materialSel.selectedIndex].value;
  5.     document.getElementById(containerSel).options.length = 0; // Empty the select box
  6.     if(material.length>0){
  7.         var index = ajax.length;
  8.         ajax[index] = new sack();
  9.  
  10.         ajax[index].requestFile = 'http://www.leadingedgeroofing.com/manage/inc/get_material_containers.php?material_type='+materialType+'&manf_id='+material;    // Specifying which file to get
  11.         ajax[index].onCompletion = function(){ createContainers(index,containerSel) };    // Specify function that will be executed after file has been found
  12.         ajax[index].runAJAX();        // Execute AJAX function
  13.     }
  14. }
  15.  
  16. function createContainers(index,containerSel) {
  17.     var obj = document.getElementById(containerSel);
  18.     eval(ajax[index].response);    // Executing the response from Ajax as Javascript code    
  19. }
  20.  
  21. function getWarrantyCost(materialSel,warrantyCost) {
  22.     var material = materialSel.options[materialSel.selectedIndex].value;
  23.     document.getElementById(warrantyCost).value = ''; // Empty the hidden input box
  24.     document.getElementById(warrantyCost + '-disabled').value = ''; // Empty the 'disabled' input box
  25.     if(material.length>0){
  26.         var index = ajax.length;
  27.         ajax[index] = new sack();
  28.  
  29.         ajax[index].requestFile = 'http://www.leadingedgeroofing.com/manage/inc/get_manufacterer_warranty.php?manf_id='+material;    // Specifying which file to get
  30.         ajax[index].onCompletion = function(){ createWarrantyCost(index,warrantyCost) };    // Specify function that will be executed after file has been found
  31.         ajax[index].runAJAX();        // Execute AJAX function
  32.     }
  33. }
  34.  
  35. function createWarrantyCost(index,warrantyCost) {
  36.     var obj = document.getElementById(warrantyCost);
  37.     var obj2 = document.getElementById(warrantyCost + '-disabled');
  38.     eval(ajax[index].response); // Executing the response from Ajax as Javascript code
  39. }
  40.  
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.
Feb 22 '08 #1
1 3278
acoder
16,027 Expert Mod 8TB
And then here's what's NOT working to try and write to the text fields, from the get_manufacturer_warranty.php file:

Expand|Select|Wrap|Line Numbers
  1. if (mysql_num_rows($warranty_r) > 0) {
  2.     echo 'obj.input = \''.mysql_result($warranty_r,0,'manf_warranty_cost').'\'; // set the value for the hidden input box
  3. obj2.input = \''.mysql_result($warranty_r,0,'manf_warranty_cost').'\'; // set the value for the disabled input box';
  4. }
  5.  
'obj.input' should be 'obj.value'.
Feb 25 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by multimatum2 | last post: by
6 posts views Thread by Peter Krikelis | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.