how show value of input select from database without click any button after select date?

Issue

   <div class="col-md-12">
                            <div class="form-group first">
                                <label >Date_reservation</label>
                                <input type="date" name="date_res">
                            </div>
                        </div>
                    <div class="row">
                        <div >
                            <div class="form-group first">
                                <label >Type_salle</label>
                                <select   name="code_salle" >

                                    <option>STD1</option>
                                    <option>STD2</option>
                                    <option>STD3</option>
                                    <option>STD4</option>

{{– In the database there is a table of rooms. I want to display here all the rooms in the room table –}}

                                </select>
                            </div>
                        </div>
                    </div>

Solution

You should change the PHP code with following code

<div class="col-md-12">
            <div class="form-group first">
                <label >Date_reservation</label>
                <input type="date" name="date_res" id="date_res">
            </div>
        </div>
        <div class="row">
            <div>
            <div class="form-group first">
                <label >Type_salle</label>
                <select name="code_salle" id="code_salle">
                   <option>STD1</option>
                   <option>STD2</option>
                   <option>STD3</option>
                   <option>STD4</option>
               </select>
           </div>
        </div>
        </div>

After that,You can use onchange function to fetch room details from the database(fetch_room_data.php, which is used to fetch the room table details from the database). Here, I will provide a sample code

$('#date_res').on('change', function() 
{                                                                  
$.ajax({
url:"fetch_room_data.php",
method:"POST",
success:function(data)
{ 
  $('#code_salle').html(data);
}
});
});

Answered By – annz

Answer Checked By – David Marino (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.