populating text box data from the database based on static drop down selected

i want to fill up the text boxes with the data from the database vales. But at the same time it should display the values according to the static drop down value selected. I am not getting how to achieve this. Here is my code

[code]

Month January February March April May June July August September October November December [/code]

In this page, it should populate the text box values fetching from the database according to the month selected. I don’t know how to do it with javascript/Ajax…

please help me in this…

I would recommend using jquery and will actually be using it to demonstrate…

html file…

  <form name="form1" action="submit.php" method="post">
    <tr bgcolor="#00BFFF">
      <td><strong>Month</strong></td>
  
    </tr>
    <tr>
      <td id='months'>
      <select id='month' name="month">
      <option value="january">January</option>
      <option value="february">February</option>
     <option value="march">March</option>
     <option value="april">April</option>
     <option value="may">May</option>
     <option value="june">June</option>
     <option value="july">July</option>
     <option value="august">August</option>
     <option value="september">September</option>
     <option value="october">October</option>
     <option value="november">November</option>
     <option value="december">December</option>
     </select>
     </td>
     <td id='days'></td>
     <input type="hidden" name="pid" value="<?php echo $product_id ?>"/>
   </tr>
   <tr><td colspan="32" align="center"><input type="submit" value="SUBMIT DATA" name="submit" style="font-size:18px; font-weight:bold;"  /></td></tr>
 
   </form>
 </table>

javascript file

$(document).ready(function(e)){

    $('#month').change(function(e){

        var month = $(this).val();

        $.get('phpFileToGetRelativeValues.php?month=' + month, function(data){

            if(data !== 'false'){
                $('#days').append(data);
            }
            else {
                alert('Something went wrong :(');
            }
        });

    });

});

phpFileToGetRelativeValues.php file…
[php]

<?php if(isset($_GET['month'])){ require 'dbConnection.php'; $month = $_GET['month']; $sql = $link->query('SELECT * FROM table JOIN otherTable USING ('fk') WHERE month = "'.$month.'"'); if($sql){ $dayNumber = 1; while($row = $sql->fetch_assoc()){ echo ' ' $dayNumber++; } } else { echo 'false'; } } [/php] I'm not guaranteeing that this code will work (even if you change the values to your required specifications) but it is a good starting point. If you have questions about what's going on at any point please feel free to ask and I will do my best to explain / help you out with it.
Sponsor our Newsletter | Privacy Policy | Terms of Service