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

  • SEARCH
  • Home
  • 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 8701673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:27:29+00:00 2026-06-13T02:27:29+00:00

I’ve created a calender-like table that updates its content via a list located in

  • 0

I’ve created a “calender”-like table that updates its content via a list located in a .PHP file. It works fine, but I’d like to be able to style it better. I would like to have the text which is currently appearing in “contentContainer” under the table, appear in the cell it belongs to. As of now, if I move the div into $calender, it loads only in the first cell.

I’d also like for the row to break at 7 columns.

<script type="text/javascript">
        var request;
        showEvents = function(caller){
            request = new XMLHttpRequest();
            request.open("GET", "getevents.php?id="+caller.id, true);
            request.onreadystatechange = updatePage(caller.id);
            request.send(null);
        };
        function updatePage(elemId){
            if(request.readyState == 4){
                var data = request.responseText;
                document.getElementById(elemId).innerHTML="<span>"+data+"</span>"
            }
        }
    </script>

<style>
table {
    width: 700px;
}
td {
    border: 1px solid;
    min-width: 100px;
    height: 100px;
    vertical-align: text-top;
    text-align: right;
    box-sizing:border-box;
    padding: 5px;
}
</style>       
</head><body>
<table border="0" cellspacing="0" cellpadding="0">
    <tr>
        <th colspan="31" scope="col">Calender</th>
    </tr>
    <tr>
    <?php
        $calendar="";
        for($i=1;$i<=31;$i++){
            $calendar .= "<td id='".$i."' onclick='showEvents(this)'><a href='#' id='".$i."'>".$i."</a> </td>";
        if (($i % 7) == 0) $calendar .= '</tr><tr>';
        }
        echo $calendar;
    ?>
    </tr>
</table>
<div id="contentContainer"></div>
</body>
</html>
  • 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-06-13T02:27:30+00:00Added an answer on June 13, 2026 at 2:27 am

    To get the 7 days across you’re looking for, I would put this in the for loop:

    if (($i % 7) == 0) $calendar .= '</tr><tr>';
    

    As for where your events pop up in the table, make sure you pass the cell’s id from showEvents to updatePage:

    request.onreadystatechange = updatePage(caller.id);
    …
    function updatePage(elemId){
    …
    document.getElementById(elemId).innerHTML="<span>"+data+"</span>"
    

    That should get you there. And to make this even more complete, I would make use of the PHP date/time functions to properly set each date in its correct place on the calendar.

    Update:

    I’ve worked on it a bit and here’s what I’ve got. For some reason, unbeknownst to me, javascript doesn’t like the two functions to be separated. That’s fixed, and I’ve also added a day of week spacer. Here’s the result:

    <script type="text/javascript">
        var showEvents = function(caller){
            request = new XMLHttpRequest();
            request.open("GET", "getevents.php?id="+caller.id, true);
            request.onreadystatechange = function () {
                if(request.readyState == 4){
                    var data = request.responseText;
                    document.getElementById(caller.id).innerHTML="<span>"+data+"</span>"
                }
            }
            request.send();
        };
    </script>
    <style>
    table {
        width: 700px;
        border-collapse: collapse;
    }
    td {
        border: 1px solid;
        min-width: 100px;
        height: 100px;
        vertical-align: text-top;
        text-align: right;
        box-sizing:border-box;
        padding: 5px;
    }
    </style>       
    </head><body>
    <table>
        <tr>
            <th colspan="7">Calendar</th>
        </tr>
        <tr>
        <?php
            $calendar="";
            $n = 0;
            $month = strtotime("2012-10-01"); // Always the first of the month
            $start = date('N', $month);
            $days = date('t',$month);
            for($i=1;$i<=$days;$i++){
                $n++;
                if ($n <= $start) { // '<=': week starts on Sunday; '<': week starts on Monday
                    $calendar .= "<td>&nbsp;</td>";
                    $i--;
                } else {
                     $calendar .= "<td id='{$i}' onclick='showEvents(this); return false;'><a href='#' id='{$i}'>{$i}</a></td>";
                }
                if (($n % 7) == 0) $calendar .= '</tr><tr>';
            }
            echo $calendar;
        ?>
        </tr>
    </table>
    <div id="contentContainer"></div>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I would like to count the length of a string with PHP. The string
I'm trying to create an if statement in PHP that prevents a single post
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.