0

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

2
Contributors
2
Replies
16
Views
3 Years
Discussion Span
Last Post by Szabi Zsoldos
0

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>");
    }
  }
});

Edited by Szabi Zsoldos

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.