Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.


I am trying to load mysql data from my database from a html select box. Here is the jquery function I am currently using, but it doesn't seem to update my results based on the selection.

$(function(){
            $('#countries').keyup(function(){

            var inpval=$('#countries').val();

            $.ajax({
                type: 'POST',
                data: ({countries : inpval}),
                url: 'data.php',
                success: function(data) {
                     $('#show_results').html(data);
          }
        });
    });
});

and here is the html code for my select box

<select id="countries">
                    <option value="canada" id="canada">canada</option>
                    <option value="america" id="america">america</option>
                    <option value="india" id="india">india</option>
                    <option value="uk" id="uk">uk</option>
                    <option value="germany" id="germany">germany</option>
                </select>

I learned how to use jquery ajax to load data from mysql database from Here, and it actually works very well for data typed into regular textboxes, however, it doesn't seem to work as well with select boxes. Any help would greatly appreciated.

Thanks.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

I think you should change your event to:

 $('#countries').change(function(){

and not keyup

share|improve this answer
 
Thanks, but it still didnt work... –  Daniel Mabinko Apr 10 '12 at 22:06
 
Do you get any javascript errors? –  Alon Apr 10 '12 at 22:07
1  
Sorry Alon, it actually worked after clearing my cache. Thanks for your help! –  Daniel Mabinko Apr 10 '12 at 22:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.