0

good day, I have a drop down box that is displayed multiple times depending on a query. How do I apply another dependent dropdown box for all the initial drop downs returned by the query? Jquery code applies to only one select box (first one) but not on others. How can we make it apply to all dropdowns Is it going to be for a each loop? I apologize as I am just a beginner on this

//Selectbox

// Selectbox
<thead>

                                <tr>
                                                <th>Cause of Failure</th>
                                                <th>Category</th>
                                                <th>Setup Status</th>
                                </tr>
    </thead>
    <tbody>

    <?php foreach($vends as $empDetails){ ?>


    <tr>


      <form action="UpdateSetup1.php?vendors=<?php echo $vendorname; ?>" method=post>
    <td>
                                                                                                    <select id=cofailure name="cofailure" style="width:150px" class="form-control">

                                                                                                                    <option value="<?php echo $empDetails['causeoffailure'];?>"><?php echo $empDetails['causeoffailure'];?></option>
                                                                                                                    <option value='Incorrect Tax ID'>Incorrect Tax ID</option>
                                                                                                                    <option value='Incorrect PIN'>Incorrect PIN</option>
                                                                                                                    <option value='No PIN on file'>No PIN on file</option>

                                                                                                    </select>
                                                                    </td>
    <td><input type=text id=category name="category" value="<?php echo $empDetails['category'];?>" readonly></td>
    <td><input type=text id=setupstatus name="setupstatus" value="<?php echo $empDetails['setupstatus'];?>" readonly></td>
    </form>

        </tr>
        <?php } ?>
        </tbody>




    //  Jquery on change
    SCRIPT


    $(document).ready(function(){
       $('#cofailure').change(function(){
                       var cofailure = $(this).val();

                       $.ajax({ 
                        url:"ajax/fetchcategory.php",
                         method:"POST",
                        data:{cofailure:cofailure},
                        success:function(data){
                        $('#category').val(data);
                        }
                       });

                        $.ajax({ 
                        url:"ajax/fetchstatus.php",
                        method:"POST",
                        data:{cofailure:cofailure},
                        success:function(data){
                        $('#setupstatus').val(data);
                        }
                       });   

   });
});
bob
  • 4,282
  • 2
  • 22
  • 30
Mackbear
  • 21
  • 2
  • Does this answer your question? [How do I attach events to dynamic HTML elements with jQuery?](https://stackoverflow.com/questions/1359018/how-do-i-attach-events-to-dynamic-html-elements-with-jquery) – Wesley Smith Jan 21 '20 at 00:09
  • @WesleySmith hi, I think that would apply to all combo boxes, if I use the myclass, what if I have more than two and I only need to apply it to one combo – Mackbear Feb 10 '20 at 18:22

0 Answers0