1

I want to make dropdown where I select the value and it can fetch data from database without submit button. I paste my code here I am student and making project I shall be very thankful to you please help...

My controller is

public function find($id)
{
    $product=$this->user_model->find($id);
    echo "ID ".$product->email;
}

Model is

public function find($id)
{
    $this->db->where('id',$id);
    return $this->db->get('users')->row();
}

View file:

<script type="text/javascript">
    $(document).ready(function() {
        $('#slt').change(function(){
            var country_id = $('#slt').val();
            $.ajax({
                type: 'GET',
                url: "<?php echo base_url('index.php/main/find/')?>"+country_id,
                success: function(result)
                {
                    $('#result').html(result);
                }
            });
        });

    });
</script>
<form>
    <input type="button" value="find" id="btnfind"/>
    <select name="opt" id="slt">
        <option value="1">one</option>
        <option value="2">two</option>
        <option value="3">one</option>
        <option value="4">two</option>
    </select>
    <br/>
    <div id="result"></div>
</form>

2 Answers 2

1
<script type="text/javascript">
$(document).ready(function(){

    $('#slt').change(function(){
        var country_id = $('#slt').val();

        $.ajax({
            type:'GET',
            data:country_id,
            url:"<?php echo base_url('index.php/main/find/')?>",
            success:function(result)
            {
                $('#result').html(result);
            }
        });
    });

});

</script>
Sign up to request clarification or add additional context in comments.

Comments

0

Change $('#result').html(result) to $('#result').text(result)

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.