1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Help with not displaying other subcategories

Discussion in 'JavaScript' started by chrisj, Feb 8, 2019.

  1. #1
    In the php web video script that I’m using, in the Upload Form, a User can choose which category to upload to. The Form also has a sub-category field to choose from. (Admin sets the subcategories, under a category).

    Upon testing (after adding a subcategory called “trees” under Category A) on the Upload Form I see Category A and have two choices for subcategories “None” and “trees”.

    But If I change my mind and decide, while the Upload Form is open, to upload to Category B, I still see the choices “None” and “trees”, even though “trees” is not a subcategory set for Category B (although if you choose Category B and trees, trees will not actually appear in the search results under Category B - so it proceeds successfully). But I believe this will cause confusion for the User/uploader.

    I am looking for suggestions as to how to fix this, so as to not show another Categories’ subcategories as choices, in the subcategory field, of the Upload Form.

    Here is some code from the main Upload Form html file:

    <div class="form-group">
            <label class="col-md-12" for="category_id">{{LANG category}}</label> 
            <div class="col-md-12">
            <select name="category_id" id="category_id" class="form-control">
            <?php foreach($pt->categories as $key => $category) {?>
            <option value="<?php echo $key?>"><?php echo $category?></option>
            <?php } ?>
            </select>
            </div>
            </div>
            <div class="form-group">
            <label class="col-md-12" for="sub_category_id">{{LANG sub_category}}</label>
            <div class="col-md-12">
            <select name="sub_category_id" id="sub_category_id" class="form-control">
            <?php echo $pt->sub_categories_array["'1'"]; ?>
            </select>
            </div>
            </div>
    HTML:
    and


    <script>
    $('.selectpicker').selectpicker({});
    <?php
    $js_array = json_encode($pt->sub_categories_array);
    echo "var sub_categories_array = ". $js_array . ";\n";
    ?>
    $(document).on('change', '#category_id', function(event) {
        event.preventDefault();
        id = $(this).val();
        $('#sub_category_id').html(sub_categories_array["'"+id+"'"]);
    });
    Code (JavaScript):
    Any guidance will be appreciated.
     
    chrisj, Feb 8, 2019 IP