Reputation: 27
In regards to answer below i have the following error in my browser console
The error is on this line according to the browser console
Uncaught TypeError: Cannot set property 'onclick' of nullcal.php:26 (anonymous function)
When the a date is clicked other than in the january, april, novemeber the form doesnt opens.
the code on like 26 is from the console browser is
document.getElementById('trigger0').onclick = function()
{showForm()};document.getElementById('trigger1').onclick = function()
{showForm()};document.getElementById('trigger2').onclick = function()
{showForm()};document.getElementById('trigger3').onclick = function()
{showForm()};document.getElementById('trigger4').onclick = function()
{showForm()};document.getElementById('trigger5').onclick = function()
{showForm()};document.getElementById('trigger6').onclick = function()
{showForm()};document.getElementById('trigger7').onclick = function()
{showForm()};document.getElementById('trigger8').onclick = function()
{showForm()};document.getElementById('trigger9').onclick = function()
{showForm()};document.getElementById('trigger10').onclick = function()
{showForm()};document.getElementById('trigger11').onclick = function()
{showForm()};document.getElementById('trigger12').onclick = function()
{showForm()};document.getElementById('trigger13').onclick = function()
{showForm()};document.getElementById('trigger14').onclick = function()
{showForm()};document.getElementById('trigger15').onclick = function()
{showForm()};document.getElementById('trigger16').onclick = function()
{showForm()};document.getElementById('trigger17').onclick = function()
{showForm()};document.getElementById('trigger18').onclick = function()
{showForm()};document.getElementById('trigger19').onclick = function()
{showForm()};document.getElementById('trigger20').onclick = function()
{showForm()};document.getElementById('trigger21').onclick = function()
{showForm()};document.getElementById('trigger22').onclick = function()
{showForm()};document.getElementById('trigger23').onclick = function()
{showForm()};document.getElementById('trigger24').onclick = function()
{showForm()};document.getElementById('trigger25').onclick = function()
{showForm()};document.getElementById('trigger26').onclick = function()
{showForm()};document.getElementById('trigger27').onclick = function()
{showForm()};document.getElementById('trigger28').onclick = function()
{showForm()};document.getElementById('trigger29').onclick = function()
{showForm()};document.getElementById('trigger30').onclick = function()
{showForm()};document.getElementById('trigger31').onclick = function()
{showForm()};document.getElementById('trigger32').onclick = function()
{showForm()};document.getElementById('trigger33').onclick = function()
{showForm()};document.getElementById('trigger34').onclick = function()
{showForm()}; function showForm(){
The code it relates to is:
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
$today = getdate();
for ($i=0; $i<($maxday+$startday); $i++) {
if(($i % 7) == 0 ) echo "<tr> ";
if($i < $startday) echo "<td></td> ";
else echo "<td align='center' valign='middle' height='20px'><a href='#'
id='trigger" . $i . "'>". ($i - $startday + 1) . "</a></td>";
$jsEvent[] = "document.getElementById('trigger" . $i . "').onclick =
function() {showForm()};";
if(($i % 7) == 6 ) echo "</tr> ";
}
?>
the javascript code
<script type="text/javascript">
<?php foreach($jsEvent as $event){
echo $event;
} ?>
function showForm(){
document.getElementById('timeslots').style.display="block";
};
</script>
Upvotes: 2
Views: 166
Reputation: 1828
You can use javascript for that. You can use onClick="" to trigger a js function that hides / shows your form.
<script type="text/javascript">
<?php foreach($jsEvent as $event){
echo $event;
} ?>
function showForm(){
document.getElementById('timeslots').style.display="block";
};
</script>
Then change
<table width='400' border='2' cellpadding='2' cellspacing='2' id='timeslots'
style="visibility:invisible"'>
to
<table width='400' border='2' cellpadding='2' cellspacing='2' id='timeslots'
style="display:none;"'>
Also change this:
<td align='center' valign='middle' height='20px'><a href='#'>". ($i - $startday + 1) . "</a></td>
to this:
<td align='center' valign='middle' height='20px'><a href='#' id='trigger" . $i . "'>". ($i - $startday + 1) . "</a></td>
Remember that "editform" is only a suggested ID and needs to match the ID of the trigger / date you are using.
I have tried and searched high and low and I am unable to come up with another soloution, Replace your for loop (the for and everything in it) with the code below
for ($i=0; $i<($maxday+$startday); $i++) {
if(($i % 7) == 0 ){
echo "<tr> ";
}
if($i < $startday){
echo "<td></td> ";
} else{
$jsEvent[] = "document.getElementById('trigger" . $i . "').onclick =
function() {showForm()};" . PHP_EOL;
echo "<td align='center' valign='middle' height='20px'><a href='#'
id='trigger" . $i . "'>". ($i - $startday + 1) . "</a></td>";
}
if(($i % 7) == 6 ){
echo "</tr> ";
}
}
The JS function could be alot more advanced, like checking or hiding other opened forms, this is just a simple JS function that displays a single form by ID
UPDATE Updated my answer according to information from comments :), now you just need to change the ID of the first document.GetelemtentByID to match the id of the "link/text" you want to trigger the function.
Upvotes: 1
Reputation: 542
I didn't read your code and I assume the the php
code mechanism works for creating the calendar, what you need is to put your form in a <div></div>
with style
attribute and store some CSS
in it that makes your division invisible which is display:none;
or visibility:hidden
. also you can set these setting in a class
attribute and put your styles in external css
. like this:
<div style="display:none;" id="calendar"><?php #your php code here ?></div>
then, you need to put a simple Java script to on the object you want to make div
visible like this:
<a onclick="document.getElementById('calendar').style.display='block'"> click me to show calendar </a>
Upvotes: 0