php – Unable to get selected id in kartik-v dependent-dropdown-ThrowExceptions

Exception or error:

I just tried using kartik-v’s dependent-dropdown jquery library. It kept on posting the text value of the option selected to the php script. However, I am not using the Yii Framework. I am just using my normal PHP.

Here is my code.
I want it to submit the actual id of the category selected instead of something like “Home”, or “Sweet”

    <select id="cat-id" class="form-control">
        <option id="">Select ...</option>
        <option id="1">Home</option>
        <option id="2">Sweet</option>
        <option id="3">Gather</option>
        <!-- other options -->

    <!-- HTML Markup (Child # 1) -->
    <select id="subcat-id" class="form-control">
        <option id="">Select ...</option>
        <!-- other options -->

            // Child # 1
                url: 'getSubcat.php',
                depends: ['cat-id']

I have tried adding this to the script

$('#cat-id').on('depdrop:change', function(event, id, value, count, textStatus, jqXHR) {

but none of these seems to work…

Please help..
Pointers or tips…

Thank you.

How to solve:

I have finally fixed it. The problem is with the options tag having ids!
Instead of id=”whatever”, it should be value=”whatever”.

Every part of the code aside the additional code I copied from the docs is fine…

Leave a Reply

Your email address will not be published. Required fields are marked *