www.webdeveloper.com
Page 3 of 3 FirstFirst 123
Results 31 to 33 of 33

Thread: Dynamically populate text box through drop down box

  1. #31
    Join Date
    May 2009
    Posts
    4
    ok hopefully this will make things less confusing...

    ok heres what the drop down looks like...
    BUT, i want it to update the DB so when the
    Code:
    <td class="dataTableContent" valign="top">
    <?php
    	         ///get the supplier info
    $supplier_array = array(array('id' => '0', 'text' => 'Select A Supplier'),
                                          array('id' => '1', 'text' => 'supplier1 - ' . $order->products[$i]['cost']),
                                          array('id' => '2', 'text' => 'supplier2 - ' . $order->products[$i]['cost2']),
                                          array('id' => '3', 'text' => 'supplier3 - ' . $order->products[$i]['cost3']),
                                          array('id' => '4', 'text' => 'supplier4 - ' . $order->products[$i]['cost4']),
                                          array('id' => '5', 'text' => 'supplier5 - ' . $order->products[$i]['cost5']),
                                          array('id' => '6', 'text' => 'supplier6 - ' . $order->products[$i]['cost6']));
    
                   echo tep_draw_pull_down_menu('update_info_name_supplier', $supplier_array, $order->info['supplier'], 'id="update_info_name_supplier" onChange="supplier(this.value)"'); 
    
    ?>
              </td>
    end of drop down however the drop down is NOT updating the database like i would like it to ... all i want it to do is to put the supplier name (supplier1 or supplier2 ... into the database field 'supplier'

    this part works perfectly IF i manually type in teh supplier name then it will pull the correct values in the next box AFTER i refresh the page... i woudl also like to eliminate having to refresh.

    Code:
    <td class="dataTableContent" valign="top"><input name="<?php echo "update_products[" . $orders_products_id . "][supplier]"; ?>" size="10" <?php if (ORDER_EDITOR_USE_AJAX == 'true') { ?>onChange="updateProductsField('update', '<?php echo $orders_products_id; ?>', 'products_supplier', encodeURIComponent(this.value))"<?php } ?> value="<?php echo $order->products[$i]['supplier']; ?>"></td>
    
    
    	        <td class="dataTableContent" valign="middle">
    <?php
    if($order->products[$i]['supplier'] == 'supplier1')
    {
    echo $order->products[$i]['cost'];
    }
    
    if($order->products[$i]['supplier'] == 'supplier2')
    {
    echo $order->products[$i]['cost2'];
    }
    
    if($order->products[$i]['supplier'] == 'supplier3')
    {
    echo $order->products[$i]['cost3'];
    }
    
    if($order->products[$i]['supplier'] == 'supplier4')
    {
    echo $order->products[$i]['cost4'];
    }
    
    if($order->products[$i]['supplier'] == 'supplier5')
    {
    echo $order->products[$i]['cost5'];
    }
    
    if($order->products[$i]['supplier'] == 'supplier6')
    {
    echo $order->products[$i]['cost6'];
    }
    ?>
    </td>
    and last but not least... in the above code where it says...

    echo $order->products[$i]['cost'];

    well rather then it pulling just that i would like it to pull the textbox like it does below however im not sure how to make that happen.

    Code:
    	        <td class="dataTableContent" valign="top"><input name="<?php echo "update_products[" . $orders_products_id . "][cost]"; ?>" size="7" <?php if (ORDER_EDITOR_USE_AJAX == 'true') { ?>onChange="updateProductsField('update', '<?php echo $orders_products_id; ?>', 'products_cost', encodeURIComponent(this.value))"<?php } ?> value="<?php echo $order->products[$i]['cost']; ?>"></td>
    
    	        <td class="dataTableContent" valign="top"><input name="<?php echo "update_products[" . $orders_products_id . "][cost2]"; ?>" size="7" <?php if (ORDER_EDITOR_USE_AJAX == 'true') { ?>onChange="updateProductsField('update', '<?php echo $orders_products_id; ?>', 'products_cost2', encodeURIComponent(this.value))"<?php } ?> value="<?php echo $order->products[$i]['cost2']; ?>"></td>
    
    	        <td class="dataTableContent" valign="top"><input name="<?php echo "update_products[" . $orders_products_id . "][cost3]"; ?>" size="7" <?php if (ORDER_EDITOR_USE_AJAX == 'true') { ?>onChange="updateProductsField('update', '<?php echo $orders_products_id; ?>', 'products_cost3', encodeURIComponent(this.value))"<?php } ?> value="<?php echo $order->products[$i]['cost3']; ?>"></td>
    
    	        <td class="dataTableContent" valign="top"><input name="<?php echo "update_products[" . $orders_products_id . "][cost4]"; ?>" size="7" <?php if (ORDER_EDITOR_USE_AJAX == 'true') { ?>onChange="updateProductsField('update', '<?php echo $orders_products_id; ?>', 'products_cost4', encodeURIComponent(this.value))"<?php } ?> value="<?php echo $order->products[$i]['cost4']; ?>"></td>
    
    	        <td class="dataTableContent" valign="top"><input name="<?php echo "update_products[" . $orders_products_id . "][cost5]"; ?>" size="7" <?php if (ORDER_EDITOR_USE_AJAX == 'true') { ?>onChange="updateProductsField('update', '<?php echo $orders_products_id; ?>', 'products_cost5', encodeURIComponent(this.value))"<?php } ?> value="<?php echo $order->products[$i]['cost5']; ?>"></td>
    
    	        <td class="dataTableContent" valign="top"><input name="<?php echo "update_products[" . $orders_products_id . "][cost6]"; ?>" size="7" <?php if (ORDER_EDITOR_USE_AJAX == 'true') { ?>onChange="updateProductsField('update', '<?php echo $orders_products_id; ?>', 'products_cost6', encodeURIComponent(this.value))"<?php } ?> value="<?php echo $order->products[$i]['cost6']; ?>"></td>
    i figured i would post that so you guys knew what i meant, hope that clears up alot of things.

  2. #32
    Join Date
    Feb 2009
    Posts
    34
    Hi EliteViper

    Thanks for the explanation but I think you'll be better off posting this Question under PHP-DB forum.
    My php and db is limited.

    So post a new thread and good luck
    Last edited by JMRKER; 07-15-2013 at 03:31 PM.

  3. #33
    Join Date
    Jul 2013
    Posts
    7

    Dynamically populate text box through drop down box

    add option is not working on this code .... can any1 help me with it.....

    PHP Code:
    <?php
    $con 
    mysql_connect("localhost","root","");
    if (!
    $con) { die('Could not connect: ' mysql_error()); }
    $db mysql_select_db("maggot") or die('Could not select DB: ' mysql_error()); 
    ?>
    <html>
    <head>
    <script type="text/javascript">
    function f1(){
    var el=document.getElementById("myTable");
    // alert(row.nodeName);  // TBODY
    var cln = el.lastChild.cloneNode(true);
    el.appendChild(cln);
    }
    function f2(){
    var tablo=document.getElementById("myTable");
    tablo.removeChild(tablo.lastChild);
    }
        var compInfoArray = new Array();
        
        <?php
            $query1 
    "SELECT * FROM lab ORDER BY id";
            
    $result1 mysql_query($query1) or die(mysql_error());
            
            
    // build javascript array
            
    while($row1=mysql_fetch_array($result1)){ 
                echo 
    'compInfoArray['.$row1['id'].'] = new Array();';
                echo 
    'compInfoArray['.$row1['id'].']["test"] = "'.$row1['test'].'";';
                echo 
    'compInfoArray['.$row1['id'].']["rate"] = "'.$row1['rate'].'";';
            }
        
    ?>
        
        function showname() {
            var id = document.form1.id.value;
            document.form1.test.value = compInfoArray[id]["test"];
            document.form1.rate.value = compInfoArray[id]["rate"];
        }
        
        window.onload=function() {
            showname();
        } 
        
    </script>

    </head>
    <body>
        <form name="form1">
        <button onClick="f1()">add</button>
    <button onClick="f2()">delete</button>
          <table >
              <tr>
                <td width="100">Select Test</td>
                <td width="170">Test Name</td>
                <td width="100">Test Rate</td>
              </tr>
              </table>
              <table id="myTable">
              <tr>
                <td width="100"><select name="id" onChange="showname()">
                  <?php
                $query1 
    "SELECT * FROM lab ORDER BY id";
                
    $result1 mysql_query($query1) or die(mysql_error());
                
                
    // build javascript array
                
    while($row1=mysql_fetch_array($result1)){ 
                    echo 
    '<option value="'.$row1['id'].'">'.$row1['test'].'</option>';
                }
            
    ?>
                </select></td>
                <td width="100"><input type="text" name="test" value="" /></td>
                <td width="100"><input type="text" name="rate" value="" /></td>
                <td>&nbsp;</td>
            </tr>
          </table>
        </form>
    </body>
    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles