How can I have the second content area display varying information as per the links in the first column?

39 Views Asked by At

I would like column 2 to display a description of each button from column 1.

The user is to be able to click on any of the buttons from column 1 and column 2 is to populate with content.

I have spent very long working with iFrames and collapsibles but cannot get it to work and my knowledge is very limited.

Do you know of a way to solve this?

<style>
* {
box-sizing: border-box;
}

.column1 {
    float: left;
    width: 40%;
    padding: 10px;
    height: 300px; 
}

.column2 {
    float: left;
    width: 60%;
    padding: 10px;
    height: 300px;
}

.row:after {
    content: "";
    display: table;
    clear: both;
}
</style>

<body>
<div class="row">
        <div class="column1" style="background-color:#aaa;">
                                                <button class="collapsible" 
data-parent="#myGroup">################</button>
                                                <button class="collapsible" 
data-parent="#myGroup">################</button>
                                                <button class="collapsible" 
data-parent="#myGroup">################</button>
                                                <button class="collapsible" 
data-parent="#myGroup">################</button>
                                                <button class="collapsible" 
data-parent="#myGroup">################</button>
                                                <button class="collapsible" 
data-parent="#myGroup">################</button>
                                                <button class="collapsible" 
data-parent="#myGroup">################</button>
                                                <button class="collapsible" 
data-parent="#myGroup">################</button>
                                            </div>
                                        <div class="column2" style="background-color:#bbb;">
                                                <p>Some text..</p>
                                        </div>
                                        </div> 
</body>
1

There are 1 best solutions below

0
On

The question is a little unclear - but I'll do what I can to assist based on what I think you're asking.

It sounds like you'd like .column2 to dynamically display data based on the button pressed in .column1. The first thing I'd recommend is to have a unique identifier on each button (an ID for example). This is going to allow you to identify which information needs to be put into .column2. Otherwise, you can check this anonymously, but that could lead you to some confusion later.

Next, you'll need to write some jQuery/JavaScript in order to listen for the button click, and then do something. For example (doing it anonymously):

$('.collapsible').click(function(){
   //do something, and eventually...
   $('.column2').html(/*the data*/);
});

Now, the next portion really depends on where you're getting your data from. One way you can do this is through a $.post() request through jQuery (Link to Documentation on $.post()) to an external source that feeds you the information (such as a PHP file). Otherwise, you could always add the data directly to the DOM (although this could get messy, along with a slough of other issues that could come from it like formatting, page speeds, etc).

If you did choose to put it into the DOM, it might look something like:

<button class="collapsible" data-parent="#myGroup" data-description="Some text pertaining to the button that the user clicked">#########</button>

And in this case, you would access this with:

$('.collapsible').click(function(){
    var description = $(this).attr('data-description');
    $('.column2').html(description);
});

Obviously you would probably want to format the data, rather than just spitting text into a div, so you could either style it based on the div, or add a paragraph/span/another DOM element around it, like:

 $('.collapsible').click(function(){
    var description = '<p class="description-class">' + $(this).attr('data-description') + '</p>';
    $('.column2').html(description);
});