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

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.12431 seconds
  • Memory Usage 2,896KB
  • Queries Executed 13 (?)
More Information
Template Usage (37):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (3)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (3)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates