Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8790885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:46:00+00:00 2026-06-13T22:46:00+00:00

I have a form that has a select field that loads the options dynamically

  • 0

I have a form that has a select field that loads the options dynamically from a db result query. Here is what the code looks like. See the description text input afterwards? I need the code to return the description of the item selected under productID. How do I go about this? Thanks very much for all replies.

    <div class="row-fluid">
    <div class="span3">
        <label>SKU</label>
        <?php  echo '<select name="ITEM" id="user" class="textfield1">';
        while($res= mysql_fetch_assoc($sql))
        {
        echo '<option value="'.$res['productID'].'">';
        echo $res['SKU'] ; 
        echo'</option>';
        }
        echo'</select>';

        ?>
    </div>
</div>
<div class="row-fluid">             
    <div class="span3">
        <label>Description</label>
        <input type="text" name="description" value=""/>
    </div>
</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:46:01+00:00Added an answer on June 13, 2026 at 10:46 pm

    You can do this in 2 ways:

    First way is by redirecting the page having a $_GET parameter which will contain the product id:

    <div class="row-fluid">
        <div class="span3">
            <label>SKU</label>
            <?php  echo '<select name="ITEM" id="user" class="textfield1" 
                          onchange="document.location=\'my-page.php?pid=\' + this.value">';
            while($res= mysql_fetch_assoc($sql))
            {
              echo '<option value="'.$res['productID'].'"';
              // LATER EDIT
                if(isset($_GET['pid']) && $_GET['pid'] == $res['productID'])
                  echo 'selected="selected"';
              // END LATER EDIT
              echo '>';
              echo $res['SKU'] ; 
              echo'</option>';
            }
            echo'</select>';
    
            ?>
        </div>
    </div>
    <div class="row-fluid">             
        <div class="span3">
            <label>Description</label>
            <?php
                if(isset($_GET['pid']) && is_numeric($_GET['pid'])) {
                    $sql = mysql_query("SELECT description 
                                        FROM products 
                                        WHERE product_id='" . mysql_real_escape_string($_GET['pid']) . "'");
                    $row = mysql_fetch_assoc($sql);
                }
            ?>
            <input type="text" name="description" value="<?=$row['description']?>"/>
        </div>
    </div>
    

    Second way is to have an ajax call and fill description input dynamically, without refresing the page

    // this is the JS code
    $(document).ready(function(){
       $('#user').change(function(){
           $.POST("my-ajax-call-page.php",
                   {pid: $("#user").val()},
                   function(data){
                       $('input[name="description"]').val(data.description);
                   }, "json");
       });
    });
    

    and your my-ajax-call-page.php should be like this:

    <?php
        include("mysql-connection.php");
    
        $sql = mysql_query("SELECT description 
                            FROM products 
                            WHERE product_id='" . mysql_real_escape_string($_POST['pid']) . "'");
        $row = mysql_fetch_assoc($sql);
    
        echo json_encode("description" => $row['description']);
    ?>
    

    You will find many examples and documentation for using jQuery library on jQuery library website

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CRUD form that has a select widget. The options in the
I have a form that has a field pulled from the database as a
I have a form that has a choice list: <select name=cellSerpro id=idcellserpro class=field text
i have a form that has a multiple select drop down. a user can
I have a form that has two field (time_selects), the idea is that the
I have a form with a table that has two input boxes, a select
I have a form that has a field that needs to be rendered as
I have a nested form that has a select dropdown menu. How can I
I have a form that has 3 types of field: (2) text fields that
I have a form that has label values that I would like to pass

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.