1

I want to retrieve value from database based on dropdown value using the ajax.
Here I'm attaching the screenshot thats what exactly I need. Once we change the year the result should be changed.

So please help me to do this task. Thanks in Advance :)

3 Answers 3

1
<script type="text/javascript">
jQuery(document).ready(function(){
  $("#district").change(function() {
    var vdcID = {"district_id" : $('#district').val()};
      $.ajax({
      type: "POST",
      data: vdcID,
      url: "<?php echo base_url(); ?>admin/ajax/showVdcById",
      dataType: 'json',
    success: function(data){
      $('#vdc').html("<option>Please Select VDC</option>  ");
        $.each(data, function(i, data){
             $('#vdc').append("<option value='"+i+"'>"+data+"</option>");
        });
       }
     });
   });
 });

this code might help you. it takes value from from a dropdown and updates value on another dropdown based on the id it sends to database

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. This solution helped me to reach to the solution somewhat .
Brother, it's helped me a lot and I would like to upvote but StackOverflow is not allowing me to do that. :( I don't have much reputation.
1

Add onchange event updateMonths() to year select tag

function updateMonths()
    {
        var selectedYear    =   $('#year').val();

        if(selectedYear!= "")
        {

            $.ajax({
                      type: "POST",
                      data: { "year":selectedYear },
                      url: "<?php echo base_url(); ?>admin/ajax/getAllMonths",
                      dataType: 'json',
                        success: function(data){

                            $.each(data, function(i, data){

                                $('#month').append($('<option>', {
                                            value: i,
                                            text: data
                                    }));
                            });
                        }
                    }); 
        }       
    }

1 Comment

i don't want to update the value in month drop down. I just want to pass the value to my controller when we select any of the year.
1

There are two ways to do it:

  1. On drop down change you can reload the entire page with appending the year in url of the page and show your result on the basis of that url appended year value.
  2. You can use ajax call on change of year drop down and load the specific content in a div.

ajax method:

var dropdownSelection = $('#dropdown_id').val();
$.ajax({
    url         : 'proccess.php',
    method      : 'get',
    data       :
    {
        selection : dropdownSelection,

    },
    success    : function(response)
    {
        $('#div_result').html(response);
    }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.