I have two tables in db named department (contains department) and sup (contains name of supervisors name).
now my query is:

By selecting the department in select menu the next select field sup should automatically get fetched with names.
how can i do it with php using onchange javascript menu..

thanks in advance

Recommended Answers

All 2 Replies

One of the simplest methods is to use jQuery's Ajax method to do this.

https://api.jquery.com/jQuery.ajax/

Example code -> not tested

$.ajax({
  url: "your_link.html",
  cache: false,
  success: function(data){
    // you can do an each sequence to append every value to the 
    // select box as options
    // I would respond with a json for the beginning
    // and iterate over every element so you can build your dropdown

    $("#your_select_box").html();
    $.each(data, function( key, value ) {
        $("#your_select_box").append("<option value='" + key + "'>" + value + "</option>");
    }
  }
});

Forgot to add after the url parameter the data: data, parameter so you can send your values to extract exactly what you need.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.