php dropdown menu population

后端 未结 4 1565
广开言路
广开言路 2021-01-01 08:31

I\'m trying to write a php script that will populate a second drop down menu based on the selection of the a primary drop down menu. I would like to use jquery to do all the

4条回答
  •  -上瘾入骨i
    2021-01-01 08:51

    Here's some code that should give you an idea of what you want to do:

    HTML

    
    
    

    PHP

     array( 'Chicago', 'Naperville', 'Decatur', 'Saint Charles' ),
            'IN' => array( 'Gary', 'Miller', 'Portage', 'Merrillville' )
        );
    
        print json_encode( $cities[ $_POST[ 'state' ] ] );
        exit;
    ?>
    

    jQuery

    jQuery(document).ready(function() {
    
        jQuery('#state').change(function() {
            jQuery.post(
                'some-url.php',
                {
                    'state':jQuery('#state').val()
                },
                function(data, textStatus) {
                    jQuery.each(data, function(index, value) {
                        jQuery('#city').append('');
                    });
                },
                'json'
            );
        });
    
    });
    

提交回复
热议问题