SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2010
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Fill value of text field based on dropdown

    What im trying to do is for each item selected from the drop down, display its value in a text box (GAC). I have attached a picture of the image to clarify.

    The drop down items are populated from a database, and each item has an associated GAC value. The remaining inputs are user supplied and all the inputs including the drop down item and its value are is stored in a different table in the database.
    Attached Images Attached Images
    Last edited by ScallioXTX; Sep 25, 2010 at 06:27. Reason: Clean up after thread split

  2. #2
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try

    html + php

    Code:
     
    <select name="mySel" id="mySel" onchange="showValue(this,elemId)">
    <option value="0">Select</option>
     
    <?php  
    $query = select gac from myTable;
    $rs = mysql_query($query, $conn);
    while($row=mysql_fetch_assoc($rs)) {
          echo '<option value="'.row['gac'].'">'.row['gac'].'</option>';
    }
    @mysql_free_result($rs);
    ?>
     
    </select>
    <input type="text" name="myInp" id="myInp" />
    javascript

    Code:
     
    function showValue(selO,elemId) {
           inpO = document.getElementById(elemId);
           inpO.value = (selO.selectedIndex == 0)? '' : selO.options[selO.selectedIndex].value;
    }


Bookmarks

Posting Permissions

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