www.webdeveloper.com
Results 1 to 6 of 6

Thread: Dynamically populate text box through drop down box

  1. #1
    Join Date
    Jul 2013
    Posts
    7

    Dynamically populate text box through drop down box

    add option is not working ...... failed to figure out the mistake done..... can anyone help me with it
    the code i have is...

    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>

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    706
    Try putting some alerts into your functions to see that they are doing what you want. Are you using any kind of debugger (in IE, hit f12?) to see any JS errors you may have?

    For your next post (?), show us the actual generated js code from your browser page - it will be more helpful.

  3. #3
    Join Date
    Jul 2013
    Posts
    7

    Dynamically populate text box through drop down box

    Quote Originally Posted by ginerjm View Post
    Try putting some alerts into your functions to see that they are doing what you want. Are you using any kind of debugger (in IE, hit f12?) to see any JS errors you may have?

    For your next post (?), show us the actual generated js code from your browser page - it will be more helpful.
    the error shows after hitting f12 is

    "HTML1527: DOCTYPE expected. The shortest valid doctype is "<!DOCTYPE html>".
    n, line 1 character 1
    "

  4. #4
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    706
    Never understood that one, but are there any others? If not, did the alerts tell you anything?

  5. #5
    Join Date
    Jul 2013
    Posts
    7

    Dynamically populate text box through drop down box

    Quote Originally Posted by ginerjm View Post
    Never understood that one, but are there any others? If not, did the alerts tell you anything?
    Even i Don't get anything from this alert....

  6. #6
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    706
    Add an alert as the last line of your add function to see that it finishes ok.

    After that I don't know. Some of you JS is new to me and I can't help you other than to have you ensure that what you have is actually function-able.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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