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:

<?phpforeach($mensas$row){?><optionvalue="<?phpecho$row['gender'] ?>"><?phpecho$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/:

<selectname="category"id ='category'style="background:transparent"><optionid ='gender'hidden="hidden">Gender</option><optionvalue="men">Men's</option><optionvalue="girl">Ladies</option></select><selectname="items"id="items"><select><scripttype="text/javascript">var dropdown_items = <?phpecho 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>');
                }
                elseif(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:

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

Post a Comment for "Jquery Onchange Issue In Php"