Skip to content Skip to sidebar Skip to footer

Jquery Onchange Issue In Php

Actually, onchange of tag need to change and display actual record for example (if change Men means mens record will open(display)) i need to pass variable inside option value how

Solution 1:

I think you are trying to get the options to populate from the $mens array:

<?php foreach($mens as $row){?>
    <option value="<?php echo $row['gender'] ?>"><?php echo $row['name'] ?></option>
<?php }?>

If this is not what you mean, you may have to clarify more.


EDIT 1:

If you have a large list of items to draw from, you will want to use ajax, but if your sample is relatively small, you can conceivably just use an array to draw from.

DEMO: https://jsfiddle.net/z50m5hnz/:

<select name="category" id ='category' style="background:transparent">
    <option id ='gender' hidden="hidden">Gender</option>
    <option value="men">Men's</option>
    <option value="girl">Ladies</option>
</select>

<select name="items" id="items">
<select>

<script type="text/javascript">
    var dropdown_items = <?php echo json_encode($mens) ?>;
    $(function () {
        $("#category").change(function () {
            var selectedText = $(this).find("option:selected").text();
            var selectedValue = $(this).val();
            var opts = [];
            $.each(dropdown_items,function(k,v){
                if(selectedValue == 'men' && v.gender == 0) {
                    opts.push('<option name="'+v.gender+'">'+v.name+'</option>');
                }
                else if(selectedValue == 'girl' && v.gender == 1) {
                    opts.push('<option name="'+v.gender+'">'+v.name+'</option>');
                }
            });

            $('#items').html(opts.join(''));
        });
    });
</script>

EDIT 2:

This is my last guess on what you want, from comments I think maybe you want to reload the page but send the the value selection:

<script type="text/javascript">
    $(function () {
        $("#category").change(function () {
            var selectedValue = $(this).val();
            window.location =   '?select='+selectedValue;
        });
    });
</script>

Post a Comment for "Jquery Onchange Issue In Php"