Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6603023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:57:05+00:00 2026-05-25T18:57:05+00:00

I have a table with multiple rows, each row has: layout (select) images *

  • 0

I have a table with multiple rows, each row has:

  • layout (select)
  • images * 10

The amount of images depends on the layout selected. I want to write some jquery code that hides/shows the amount of images depending on the layout selected/changed.

At the moment I have this which doesn’t work correctly and only shows 1 image each time.

$('select.layouts').bind("change keyup",function(){
var val = $(this).val();
switch(val){
case 1:
    showImgs = 1;
    break;
case 2:
    showImgs = 2;
    break;
case 3:
    showImgs = 3;
    break;
case 4:
    showImgs = 4;
    break;
default:
    showImgs = 1;
}
$(this).parents("tr").find(".images .image:lt("+showImgs+")").show();
})

Also would it be best practice to instead of adding how many images per layout into the JS code, I have a data attribute to the select option?

HTML Table

<table class="list" id="images">
    <thead>
        <tr>
            <td>Layout:</td>
            <td>Image:</td>
        </tr>
    </thead>
    <tbody id="image-row0">
        <tr>
            <td>
                <select class="layouts" name="banner_image[0][layout]">
                    <option value="1">Layout 1</option>
                    <option selected="selected" value="2">Layout 2</option>
                    <option value="3">Layout 3</option>
                    <option value="4">Layout 4</option>
                    <option value="5">Layout 5</option>
                    <option value="6">Layout 6</option>
                    <option value="7">Layout 7</option>
                    <option value="8">Layout 8</option>
                    <option value="9">Layout 9</option>
                    <option value="10">Layout 10</option>
                </select>
            </td>
            <td class="left images">
                <div style="display: none" class="image">
                    <label for="thumb0">Image 1</label><br>
                    <input type="hidden" id="image0" value="data/slides/dd1.png" name="banner_image[0][image]"> <br>
                </div>
                <div style="display: none" class="image">
                    <label for="thumb20">Image 2</label><br>
                    <input type="hidden" id="image20" value="data/slides/dd1.png" name="banner_image[0][image2]"> <br>
                </div>
                <div style="display: none" class="image">
                    <label for="thumb30">Image 3</label><br>
                    <input type="hidden" id="image30" value="data/slides/dd1.png" name="banner_image[0][image3]"> <br>
                </div>
                <div style="display: none" class="image">
                    <label for="thumb40">Image 4</label><br>
                    <input type="hidden" id="image40" value="data/slides/dd1.png" name="banner_image[0][image4]"> <br>
                </div>
                <div style="display: none" class="image">
                    <label for="thumb50">Image 5</label><br>
                    <input type="hidden" id="image50" value="data/slides/dd1.png" name="banner_image[0][image5]"> <br>
                </div>
                <div style="display: none" class="image">
                    <label for="thumb60">Image 5</label><br>
                    <input type="hidden" id="image60" value="data/slides/dd1.png" name="banner_image[0][image6]"> <br>
                </div>
            </td>
        </tr>
    </tbody>
    <tbody id="image-row1">
        <tr class="odd">
            <td>
                <select class="layouts" name="banner_image[1][layout]">
                    <option selected="selected" value="1">Layout 1</option>
                    <option value="2">Layout 2</option>
                    <option value="3">Layout 3</option>
                    <option value="4">Layout 4</option>
                    <option value="5">Layout 5</option>
                    <option value="6">Layout 6</option>
                    <option value="7">Layout 7</option>
                    <option value="8">Layout 8</option>
                    <option value="9">Layout 9</option>
                    <option value="10">Layout 10</option>
                </select>
            </td>
            <td class="left images">
                <div style="display: none" class="image">
                    <label for="thumb0">Image 1</label><br>
                    <input type="hidden" id="image0" value="data/slides/dd1.png" name="banner_image[0][image]"> <br>
                </div>
                <div style="display: none" class="image">
                    <label for="thumb20">Image 2</label><br>
                    <input type="hidden" id="image20" value="data/slides/dd1.png" name="banner_image[0][image2]"> <br>
                </div>
                <div style="display: none" class="image">
                    <label for="thumb30">Image 3</label><br>
                    <input type="hidden" id="image30" value="data/slides/dd1.png" name="banner_image[0][image3]"> <br>
                </div>
                <div style="display: none" class="image">
                    <label for="thumb40">Image 4</label><br>
                    <input type="hidden" id="image40" value="data/slides/dd1.png" name="banner_image[0][image4]"> <br>
                </div>
                <div style="display: none" class="image">
                    <label for="thumb50">Image 5</label><br>
                    <input type="hidden" id="image50" value="data/slides/dd1.png" name="banner_image[0][image5]"> <br>
                </div>
                <div style="display: none" class="image">
                    <label for="thumb60">Image 5</label><br>
                    <input type="hidden" id="image60" value="data/slides/dd1.png" name="banner_image[0][image6]"> <br>
                </div>
            </td>
        </tr>
    </tbody>
</table>

EDIT: @Kalle H. Väravas code

var layouts_data = {
    0: {
        name: 'None',
        images: 0
    },
    1: {
        name: 'Layout 1',
        images: 1
    },
    2: {
        name: 'Layout 2',
        images: 4
    },
    3: {
        name: 'Layout 3',
        images : 6
    },
    4: {
        name: 'Layout 4',
        images: 4
    },
    5: {
        name: 'Layout 5',
        images: 5
    }
};


SetLayout = function (row, layoutid) {
    var current_layout = layouts_data[layoutid];
    $(row).find('.image').hide().each(function (i, elm) {
        if ((i + 1) <= current_layout['images']) {
            $(elm).show();
        }
    });
};

$(document).ready(function () {
    $('#images tbody tr').each(function(i, elm) {
        SetLayout($(this), $(this).find('select.layouts option:selected').val());
    });
});

// Lets catch the event
$('select.layouts').bind("change keyup", function () {
    SetLayout($(this).parents("tr"), $(this).val()); 
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:57:05+00:00Added an answer on May 25, 2026 at 6:57 pm

    Revision 1

    As reading your comments and understand the issue better. I have composed a nice little layout-array. This way you can store more data and basically just pick the layout with the select.

    http://jsfiddle.net/hobobne/FxU6V/1/

    General idea stays the same, but little bit more complex.

    Original

    I might have understood you wrong, but this is what I got to offer:

    <style>
    .imgs {margin: 5px; width: 100px; height: 100px; float: left; display: none;}
    </style>
    Show how many images: <select name="show-images">
        <option>1</option>
        <option>2</option>
        <option>3</option>
        <option>4</option>
        <option>5</option>
    </select>
    <div class="imgs" style="background: yellow;"></div>
    <div class="imgs" style="background: blue;"></div>
    <div class="imgs" style="background: green;"></div>
    <div class="imgs" style="background: brown;"></div>
    <div class="imgs" style="background: pink;"></div>
    <script>
    $('select[name="show-images"]').bind("change keyup", function () {
        var images_amount = $('select[name="show-images"] option:selected').text();
        $('.imgs').hide().each(function (i, elm) {
            if ((i + 1) <= images_amount) {
                $(elm).show();
            }
        });
    });
    </script>
    

    [ View output ]

    For this example, I used colorful containers instead of the images, but technically it doesn’t matter. And as you can see, the fiddle contains comments, so you can understand each step 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with multiple rows. Each row is a form. I want
I have a table that contains multiple rows. Each row contains 5 columns (or
I have a table with game scores, allowing multiple rows per account id: scores
I have multiple rows in a table, in one of which is a link
I have a table with a Date column. Each Date may appear multiple times.
I have a process that needs to select rows from a Table (queued items)
I am creating a dynamic table of three columns and multiple rows. I want
I Have Table with multiple columns and rows, Example, <table> <thead> <tr> <th>Head 1</th>
I have a table UserAliases ( UserId, Alias ) with multiple aliases per user.
I have a table with columns Index, Date where an Index may have multiple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.