PHP / JS - Pop up Calendar (date picker)

Small, short code snippets that other people may find useful. Do you have a good regex that you would like to share? Share it! Even better, the code can be commented on, and improved.

Moderator: General Moderators

User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

PHP / JS - Pop up Calendar (date picker)

Post by Burrito »

I was browsing the forums today looking for a good popup calendar and couldn't find any that I liked. I found some JS ones out there, but they a PITA to get looking exactly how I like. While looking through the forums I also noted that someone wanted a php solution for a simple JS pop-up calendar (date picker)...so I wrote one :D...super easy to make look how you want, just change the styles:

see it working here

Code: Select all

<script>
function popCal(where,fn){
	var dateon = (document.forms[fn].date.value !== "" ? document.forms[fn].date.value : "");
	if(dateon !== ""){
		dateon = dateon.split("/");
		dateon = dateon[2]+"-"+dateon[0]+"-"+dateon[1];
	}	
	var cal = window.open("smallcal.php?where="+where+"&fn="+fn+"&dateon="+dateon,"smallcal","width=300,height=300");
	cal.focus();
}
</script>
<form name="MyForm">
<a href="javascript:popCal('dateField','MyForm')"><img src="images/calendar.gif" border="0"></a> <input type="text" name="dateField">
</form>

Code: Select all

<?
//////////////////////////////////////////////////////////////////////
//					Pop-Up Calendar by: Burrito						//
//																	//
//							03-22-2005								//
//																	//
//				PHP Replacement For JS Calendars					//
//																	//
//////////////////////////////////////////////////////////////////////

// set date for month...default is today...Burrito
if($_GET['dateon'] == "" && !isset($_GET['yr'])){
	$datetime = date("m/d/Y", time());
	$mo = date("n", time());
	$yr = date("Y", time());
	$da = date("d", time());
}else if(!isset($_GET['yr'])){
	$datetime = date("m/d/Y", strtotime($_GET['dateon']));
	$mo = date("n", strtotime($_GET['dateon']));
	$yr = date("Y", strtotime($_GET['dateon']));
	$da = date("d", strtotime($_GET['dateon']));
	
}else{
	$datetime = date("m/d/Y", strtotime($_GET['mo']."/01/".$_GET['yr']));
	$mo = $_GET['mo'];
	$yr = $_GET['yr'];
	$da = "";
}
// find last day of the month for given month/year...burrito
$dim = date("t", strtotime($datetime));



?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
	<title>Calendar</title>
<style>
.parent
{
border: 1px #2b2c33 solid;
}
.prow
{
border-bottom: 1px #2b2c33 solid; border-right: 1px #2b2c33 solid;
}
.headRow
{
font-family:tahoma; font-size:9.5pt; color:#506749; font-weight:bold;
}
.row
{
font-family:tahoma; font-size:9pt; color:#506749
}
td.cell
{
font-family:tahoma; font-size:9pt; color:#506749
}
select,input
{
font-family:tahoma; font-size:9pt; color:#506749; background-color:#e4ddc0; border: 1px #273536 solid;
}
td.days
{
font-family:tahoma; font-size:9pt; color:#000000; background-color:#c3c3c3;
border-bottom: 1px #2b2c33 solid; border-right: 1px #2b2c33 solid; overflow:auto
}
td.nodays
{
font-family:tahoma; font-size:9pt; color:#909090; background-color:#dfdfdf;
border-bottom: 1px #2b2c33 solid; border-right: 1px #2b2c33 solid; overflow:auto
}
td.tday
{
font-family:tahoma; font-size:9pt; color:#000000; background-color:#919191;
border: 1px #2b2c33 solid; overflow:auto
}
.gr
{
color:#374248
}
td.full
{
font-family:tahoma; font-size:9pt; color:#000000; background-color:#C99797;
border-bottom: 1px #2b2c33 solid; border-right: 1px #2b2c33 solid;
}
</style>
<script>
function updateParent(what,when,yrwhen){
	var month = (when ? when : "<?=$mo;?>");
	var year = (yrwhen ? yrwhen : "<?=$yr;?>");
	opener.document.<?=$_GET['fn'].".".$_GET['where'];?>.value = month+"/"+what+"/"+year;
	window.close();
}
</script>
</head>

<body>

			<table width="99%" cellspacing="0" align="center" class="parent" height="95%">
			<tr>
			<td colspan="7" align="center" class="prow" height="10">
			<form action="smallcal.php">
			<select name="mo">
				<option value="1" <?=($mo == "1" ? "selected=\"selected\"" : ""); ?>>January</option>
				<option value="2" <?=($mo == "2" ? "selected=\"selected\"" : ""); ?>>February</option>
				<option value="3" <?=($mo == "3" ? "selected=\"selected\"" : ""); ?>>March</option>
				<option value="4" <?=($mo == "4" ? "selected=\"selected\"" : ""); ?>>April</option>
				<option value="5" <?=($mo == "5" ? "selected=\"selected\"" : ""); ?>>May</option>
				<option value="6" <?=($mo == "6" ? "selected=\"selected\"" : ""); ?>>June</option>
				<option value="7" <?=($mo == "7" ? "selected=\"selected\"" : ""); ?>>July</option>
				<option value="8" <?=($mo == "8" ? "selected=\"selected\"" : ""); ?>>August</option>
				<option value="9" <?=($mo == "9" ? "selected=\"selected\"" : ""); ?>>September</option>
				<option value="10" <?=($mo == "10" ? "selected=\"selected\"" : ""); ?>>October</option>
				<option value="11" <?=($mo == "11" ? "selected=\"selected\"" : ""); ?>>November</option>
				<option value="12" <?=($mo == "12" ? "selected=\"selected\"" : ""); ?>>December</option>
			</select>
			<select name="yr">
				<?for($a=2002;$a<2021;$a++){
				echo "<option value=\"".$a."\"".($yr == $a ? "selected=\"selected\"" : "").">".$a."</option>";
				}?>
			</select>
			<input type="submit" value="go">
			<input type="hidden" name="dateon">
			<input type="hidden" name="where" value="<?=$_GET['where'];?>">
			<input type="hidden" name="fn" value="<?=$_GET['fn'];?>">
			</form></td>
			</tr>
			<tr>
			<td colspan="7" align="center" class="prow" height="10">
			<span class="headRow"><?=date("F",strtotime($datetime))." ".date("Y",strtotime($datetime));?></span>
			</td>
			</tr>
			<tr>
			<td width="14%" align="center" class="prow" height="10"><span class="row">Su</span></td>
			<td width="14%" align="center" class="prow" height="10"><span class="row">Mo</span></td>
			<td width="14%" align="center" class="prow" height="10"><span class="row">Tu</span></td>
			<td width="14%" align="center" class="prow" height="10"><span class="row">We</span></td>
			<td width="14%" align="center" class="prow" height="10"><span class="row">Th</span></td>
			<td width="14%" align="center" class="prow" height="10"><span class="row">Fr</span></td>
			<td width="14%" align="center" class="prow" height="10"><span class="row">Sa</span></td>
			</tr>
			<tr>
			<? 
			// get the first day of the month...burrito
			$firstofmonth = date("m/1/Y", strtotime($datetime));
			// get first day of the month by day of week in string format...burrito
			$dow = date("D", strtotime($firstofmonth));
			// make a number representation of the first day of the month by day of week...burrito
			switch($dow){
				case "Sun":
				$dowi = 1;
				break;
				case "Mon":
				$dowi = 2;
				break;
				case "Tue":
				$dowi = 3;
				break;
				case "Wed":
				$dowi = 4;
				break;
				case "Thu":
				$dowi = 5;
				break;
				case "Fri":
				$dowi = 6;
				break;
				case "Sat":
				$dowi = 7;
				break;
			}
			$dw = $dowi - 1;
			// pad the calendar for empty days at the beginning of the month...burrito
			// get last few days of previous month...burrito
			$lastdays = date("t", strtotime($mo."/01/".$yr." -1 month"));
			$lastdays = $lastdays - $dw +1;
			$lastmo = ($mo !== "1" ? $mo - 1 : 12);
			$lastyr = ($mo !== "1" ? $yr : $yr - 1);
			for($i=1;$i<$dowi;$i++){
				echo "<td width=\"14%\" class=\"nodays\" align=\"center\" style=\"cursor:hand\" onClick=\"updateParent('".$lastdays."','".$lastmo."','".$lastyr."')\">".$lastdays."</td>";
				$lastdays++;
			}
			
			// loop the days and add day of month...burrito
			$rn = 1;
			for($j=1;$j<$dim+1;$j++){
				if($j == $da){
					$cl = "tday";
				}else{
					$cl = "days";
				}
				
								
				echo "<td id=\"i".$j."\" width=\"14%\" class=\"".$cl."\" style=\"cursor:hand\" onMouseOver=\"this.style.backgroundColor='#FFFFFF'\" onMouseOut=\"this.style.backgroundColor=''\" align=\"center\" onClick=\"updateParent('".$j."')\"><b>".$j."</b></td>";
				$dw++;
				// find out if need to start a new row for next week...burrito
				if($dw == "7"){
					$rn++;
					echo "</tr>";
					$dw = 0;
				}
				
			}
			
			
			
			// pad the calendar for days after the last day of the month...burrito
			$topad = 7 - $dw;
			$enddays = 1;
			if($topad < 7){
			$nextmo = ($mo !== "12" ? $mo + 1 : 1);
			$nextyr = ($mo !== "12" ? $yr : $yr + 1);
				for($k=1;$k<$topad+1;$k++){
					echo "<td width=\"14%\" class=\"nodays\" align=\"center\" style=\"cursor:hand\" onClick=\"updateParent('".$enddays."','".$nextmo."','".$nextyr."')\">".$enddays."</td>";
					$enddays++;
				}
			}
			echo "</tr></table>";
?>
</body>
</html>
see it working here

Enjoy,

Burr


feyd | unscrewed the old php tag junk
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Very nice....

Nice code :wink:
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

cool.

i like muchly!!

Gonna use this me thinks.
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post by ljCharlie »

It is very nice. However, I couldn't get it work. I'm guessing it has to do with this code:

Code: Select all

<a href=&quote;javascript:popCal('dateField','MyForm')&quote;><img src=&quote;images/calendar.gif&quote; border=&quote;0&quote;></a>
When I clikced on it, nothing happens. I put an alert() message inside the function function popCal(where,fn){ } and that alert() message is not even pop up so I'm not sure what's going on.

ljCharlie
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

post your code.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Hi,

I used this in an application yesterday.

Had to make a few changes for my needs:

1)In my application, there were more than one field that needed a date entering, so changed the code slightly to update the correct field, dependant on which you clicked

2)Changed the date format to dd/mm/yy

3)Added the ability to define what date is shown when the popup is created, on a per popup basis
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Why not share the updates ;)
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

You asked for it, so here are the changes i made.

If you need more than one date filed on the page, you need to tell the script which one you are updating...to do this change this line

Code: Select all

var dateon = (document.forms[fn].date.value !== "" ? document.forms[fn].date.value : "");
to..

Code: Select all

var dateon = (document.forms[fn][where].value !== "" ? document.forms[fn][where].value : "");
Then, on you link just replace "dateField" with the name of the fieled you want to update...like so...

Code: Select all

<a href="javascript:popCal('dateField','MyForm')"><img src="images/calendar.gif" border="0"></a>

Next up was making the calender display the date in the dd/mm/yy format.
This was simply done by changing...

Code: Select all

if(dateon !== ""){
     dateon = dateon.split("/");
     dateon = dateon[2]+"-"+dateon[0]+"-"+dateon[1];
}


to...

Code: Select all

if(dateon !== ""){
        dateon = dateon.split("/");
        dateon = dateon[2]+"-"+dateon[1]+"-"+dateon[0];
    }
and in smallcal.php change the following line...

Code: Select all

opener.document.<?=$_GET['fn'].".".$_GET['where'];?>.value = month+"/"+what+"/"+year;
to...

Code: Select all

opener.document.<?=$_GET['fn'].".".$_GET['where'];?>.value = what+"/"+month+"/"+year;

Finally, i added th ability to choose what date the popup window opened on.

This was done by doing the following...

changing...

Code: Select all

function popCal(where,fn){
to...

Code: Select all

function popCal(where,fn,start_date){
adding the following...

Code: Select all

if(start_date){
    dateon = start_date.split("/");
    dateon = dateon[2]+"-"+dateon[1]+"-"+dateon[0];
}
after...

Code: Select all

if(dateon !== ""){
        dateon = dateon.split("/");
        dateon = dateon[2]+"-"+dateon[1]+"-"+dateon[0];
    }
and altering the link to pass the third variable which is the date you want the calendar to open at...

Code: Select all

<a href="javascript:popCal('summer2005_to','application', '1/6/2005')"><img src="/images/calendar.gif" border="0"></a>
Hope this helps.

Mark
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

I recomend changing the year drop down to:

Code: Select all

$start_year = date("Y")-5;
   $end_year = date("Y")+20;

This will allow for more dynamic calendars. Such as "Please select your birthdate"

Code: Select all

$start_year = date("Y")-100;
   $end_year = date("Y");

   <select name="yr">
        <?for($a=$start_year;$a<=$end_year;$a++){
        echo "<option value=\"".$a."\"".($yr == $a ? "selected=\"selected\"" : "").">".$a."</option>";
        }?>
    </select>
Small change but could be useful
8kobe
Forum Newbie
Posts: 14
Joined: Sun Mar 05, 2006 11:35 am

Post by 8kobe »

Picture is in next post, basically puts calendar on screen, instead of popup.

I am having a problem getting this working correctly, can someone give me a hand on it. Okay I took the larger file that you posted and saved it as datechooser.php I then included that file. Here is the contents of the page where I am trying to include it

Code: Select all

function insert_project($conn)
{ 
    if($_POST[submit] != "")
        {
        // process form
        $sql = "INSERT INTO Project (comp_ID,projName,projStartDate,projOwner,projEnddate,projStatus,projDept,projPercentComp,projColorIdnt,projURL,projDemoURL,projDescription,projCreator,projActive,projPriority,projType) VALUES ('$_POST[compId]','$_POST[projName]','$_POST[projStartDate]','$_POST[projOwner]', '$_POST[projEnddate]','$_POST[projStatus]', '$_POST[projDept]','$_POST[projPercentComp]','$_POST[projColorIdnt]', '$_POST[projURL]','$_POST[projDemoURL]','$_POST[projDescription]','$_POST[projCreator]','$_POST[projActive]','$_POST[projPriority]','$_POST[projType]')";
        $result = mysql_query($sql, $conn) or die (mysql_error());

	$ID=mysql_insert_id($conn);
	$fl=new FileList("../../files/$ID");
    
        echo "Data submitted";
        }
        else
        {
        //Date Chooser
        echo"<script>
        function popCal(where,fn){
        var dateon = (document.forms[fn].date.value !== \"\" ? document.forms[fn].date.value : \"\");
        if(dateon !== \"\"){
        dateon = dateon.split(\"/\");
        dateon = dateon[2]+"-"+dateon[0]+\"-\"+dateon[1];
        }
        var cal = window.open(\"../../datechooser.php?where=\"+where+\"&fn=\"+fn+\"&dateon=\"+dateon,\"smallcal\",\"width=300,height=300\");
        cal.focus();
        }
        </script>";
        //Date Chooser

        //SQL Statement to get a company list
        $sql = "SELECT * from Company";
        $result = mysql_query($sql, $conn) or die (mysql_error());
        $tmparray=array();
            while ($row = mysql_fetch_array($result))
            {
            extract($row);
            $company_array[$compID] = "$compName";
            }
        //SQL Statement to get a user List
        $sql ="SELECT * from User";
        $result = mysql_query($sql, $conn) or die (mysql_error());
        $tmparray2=array();
            while ($row = mysql_fetch_array($result))
            {
            extract($row);
            $user_array[$userID]= "$userName";
            }

        //Form portion for Company Name

        echo "
        <br>
        <center>
        <table cellspacing='0' cellpadding='4' border='0' width='100%' class='inserttable'>
        <form name=\"inPrj\" method='post' action='$_SERVER[PHP_SELF]'>";
        
        echo "
        <tr>
		<td width='50%' valign='top'>
		<table cellspacing='0' cellpadding='2' border='0'>
		<tr>
			<td align='right' nowrap='nowrap'>Company Name:</td>
			<td width='100%' colspan='2'><select name=\"compId\">";
        $temparray=array_keys($company_array);
        foreach($temparray as $i)
        {
        echo"
        <option value=$i>$company_array[$i]</option>";
        }
        echo"
        </select>
        </td>
        </tr>";
        //End form portion for Company Name

        echo "
		<tr>
			<td align='right' nowrap='nowrap'>Project Name:</td>
			<td colspan='2'><input type='Text' name='projName'><font color='red'>*</font></td>
		</tr>";

        
        echo "
        <tr>
        	<td align='right' nowrap='nowrap'>Project Start Date:</td>
        	<td width='100%' nowrap='nowrap' colspan='2'><input type='Text' name='projStartDate'><a href=\"javascript:popCal('projStartDate','inPrj')\"><img src=\"../../images/calendar.gif\" border=\"0\"></a></td>
        </tr>";
        
        echo "
        <tr>
			<td align='right' nowrap='nowrap'>Project Manager</td>
			<td nowrap='nowrap'><select name=\"projOwner\">";
        $temparray=array_keys($user_array);
        foreach($temparray as $i)
        {
        echo"
        <option value=$i>$user_array[$i]</option>";
        }
        echo"
        </select><br></td>
        </tr>";
        //End Form Portion for Project Manager


			
		echo "
		<tr>
			<td align='right' nowrap='nowrap'>Project End Date:</td>
			<td nowrap='nowrap'><input type='Text' name='projEnddate'></td>
		</tr>";
                
        echo "
        <tr>
			<td align='right' nowrap='nowrap'>Project Status:</td>
			<td nowrap><select name=\"projStatus\">
	        <option value=\"Proposed\">Proposed</option>
    	    <option value=\"In Progress}\">In Progress</option>
        	<option value=\"Complete\">Complete</option>
        	<option value=\"Archived\">Archived</option>
        	</select></td>
		</tr>";
		
		echo "
		<tr>
			<td colspan='2'><hr noshade='noshade' size='1'></td>
		</tr>";
				
		
		echo "
		<tr>
			<td align='right' nowrap='nowrap'>Project Department:</td>
			<td colspan='2'><input type='Text' name='projDept'></td>
		</tr>";
		
		
		echo "
		<tr>
			<td align='right' nowrap='nowrap'>Project Percent Completed:</td>
			<td colspan='2'><select name=\"projPercentComp\">";
			
		for($i=0; $i<=100; $i=$i+5)
                {
        echo"<option value=$i>$i%</option>";
        }
        echo" 
        </select></td>
        </tr>";	
		//Project Percent complete loop from 0-100
        //End Project Percent Complete loop from 0-100
        //Form portion for Color Identifier
		
        //end of left table
        echo "
        <tr>
			<td align='right' colspan='3'></td>
		</tr>
		</table>
		</td>";
		
        
        
        echo "
    	<td width='50%' valign='top'>
		<table cellspacing='0' cellpadding='2' border='0' width='100%'>
		<tr>
			<td align='right' nowrap='nowrap'>Project Color Identifier:</td>
			<td nowrap><select name=\"projColorIdnt\">
	        <option value=\"c0c0c0\" style=\"background-color:c0c0c0\">Silver</option>
    	    <option value=\"4c4c4c\" style=\"background-color:4c4c4c\">Gray</option>
        	<option value=\"ccccff\" style=\"background-color:ccccff\">Light Gray</option>
        	<option value=\"9966cc\" style=\"background-color:9966cc\">Purple</option>
        	<option value=\"ccffff\" style=\"background-color:ccffff\">Light Blue</option>
        	<option value=\"00cccc\" style=\"background-color:00cccc\">Turquoise</option>
        	<option value=\"008000\" style=\"background-color:008000\">Green</option>
        	<option value=\"0000ff\" style=\"background-color:0000ff\">Blue</option>
        	<option value=\"ffff66\" style=\"background-color:ffff66\">Yellow</option>
        	<option value=\"ffcc99\" style=\"background-color:ffcc99\">Peach</option>
        	<option value=\"eb613d\" style=\"background-color:eb613d\">Light Red</option>
        	<option value=\"ff3366\" style=\"background-color:ff3366\">Pink</option>
        	<option value=\"ff0000\" style=\"background-color:ff0000\">Red</option>
        	</select></td>
		</tr>";
        //End Form portion for Color Identifier
		
		echo "
		<tr>
			<td align='right' nowrap='nowrap'>Project URL:</td>
			<td colspan='3'><input type='Text' name='projURL' value='http://'></td>
		</tr>";
			
		
		echo "
		<tr>
			<td align='right' nowrap='nowrap'>Project Demo URL:</td>
			<td nowrap='nowrap'><input type='Text' name='projDemoURL' value='http://'></td>
		</tr>";
		
		
		//Form Portion for Project Creator
        echo"
        <tr>
        	<td align='right' nowrap='nowrap'>Project Creator:</td>
        	<td nowrap='nowrap'><select name=\"projCreator\">";
        $temparray=array_keys($user_array);
        foreach($temparray as $i)
        {
        echo"
        <option value=$i>$user_array[$i]</option>";
        }
        echo" 
        </select></td>
        </tr>";
        //End Form Portion for Project Creator
		
        
        //Form portion for project active
        echo"
        <tr>
        	<td align='right' nowrap='nowrap'>Project Active:</td>
        	<td nowrap='nowrap'><select name=\"projActive\">
        		<option value=\"0\">Active</option>
        		<option value=\"1\">Not Active</option>
        	</select></td>
        </tr>";
        //end Form Portion for project active
        
        
        
        //Project Priority loop from 0-4
        echo"
        <tr>
        	<td align='right' nowrap='nowrap'>Project Priority:</td>
        	<td nowrap='nowrap'><select name=\"projPriority\">";
        for($i=0; $i<=4; $i++)
        {
        echo"
        <option value=$i>$i</option>";
        }
        echo"
        </select></td>
        </tr>";
        //End Project Priority loop from 0-4

        
        
        //Form portion for project type
        echo"
        <tr>
        	<td align='right' nowrap='nowrap'>Project Type:</td>
        	<td nowrap='nowrap'><select name=\"projType\">
        		<option value=\"Type 1\">Type 1</option>
        		<option value=\"Type 2\">Type 2</option>
        		</select></td>
        </tr>";
        //end Form Portion for project type
		
        
		
		echo "
		<tr>
			<td colspan='4'>Project Description:<br />
			<textarea name='project_description' cols='50' rows='10' wrap='virtual' class='textarea'></textarea>
			</td>
		</tr>";


		echo "
		</table>
		</td>
		</tr>
		
		<tr>
		<td>
		<font color='red'>*</font> required		
		</td>
		
		
		<td>
		<input class='button' type='Submit' name='submit' value='Enter information'>
		</td>

		</td>

		</tr>
		</form>
		</table>
		</td>
		</tr>
		</table>
		</center>";
 		
        }
}

The problem I am getting currently is that it is displaying the calendar (The whole thing) on the top of the page, and the little calendar is not popping up. Thanks ahead of time.
Last edited by 8kobe on Sun Mar 12, 2006 5:31 pm, edited 1 time in total.
8kobe
Forum Newbie
Posts: 14
Joined: Sun Mar 05, 2006 11:35 am

Post by 8kobe »

Image
ichversuchte
Forum Newbie
Posts: 9
Joined: Thu Nov 10, 2005 12:05 pm

Help with the calendar code....

Post by ichversuchte »

How come am I getting this error...


Parse error: parse error, unexpected T_IS_EQUAL in /home/forthest/public_html/cal/smallcal.php on line 108

This is the code from line 108.....

Code: Select all

<select name="mo">
                                <option value="1" <?php =($mo == "1" ? "selected="selected"" : ""); ?> >January</option>
                                <option value="2" <?php =($mo == "2" ? "selected="selected"" : ""); ?>>February</option>
                                <option value="3" <?php =($mo == "3" ? "selected="selected"" : ""); ?>>March</option>
                                <option value="4" <?php =($mo == "4" ? "selected="selected"" : ""); ?>>April</option>
                                <option value="5" <?php =($mo == "5" ? "selected="selected"" : ""); ?>>May</option>
                                <option value="6" <?php =($mo == "6" ? "selected="selected"" : ""); ?>>June</option>
                                <option value="7" <?php =($mo == "7" ? "selected="selected"" : ""); ?>>July</option>
                                <option value="8" <?php =($mo == "8" ? "selected="selected"" : ""); ?>>August</option>
                                <option value="9" <?php =($mo == "9" ? "selected="selected"" : ""); ?>>September</option>
                                <option value="10" <?php =($mo == "10" ? "selected="selected"" : ""); ?>>October</option>
                                <option value="11" <?php =($mo == "11" ? "selected="selected"" : ""); ?>>November</option>
                                <option value="12" <?php =($mo == "12" ? "selected="selected"" : ""); ?>>December</option>
                        </select>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

because you've converted the script from short tags to standard tags but neglected to convert the short tag echo (the equal)
ichversuchte
Forum Newbie
Posts: 9
Joined: Thu Nov 10, 2005 12:05 pm

Post by ichversuchte »

Im sorry, but i am just starting out with php, what I gathered from your post was that i changed it from <? to <?php and didn't update the single = sign to == ... such as the below, but if thats the case i get this error?

Is there anyway you could give me more direction. I did take the code directly out of your first post and i got the same error, so i updated the tags and I am stilll having issues....

Parse error: parse error, unexpected T_IS_EQUAL in /home/forthest/public_html/cal/smallcal.php on line 108

Code: Select all

<select name="mo">
                                <option value="1" <?php ==($mo == "1" ? "selected="selected"" : ""); ?>>January</option>
                                <option value="2" <?php ==($mo == "2" ? "selected="selected"" : ""); ?>>February</option>
                                <option value="3" <?php ==($mo == "3" ? "selected="selected"" : ""); ?>>March</option>
                                <option value="4" <?php ==($mo == "4" ? "selected="selected"" : ""); ?>>April</option>
                                <option value="5" <?php ==($mo == "5" ? "selected="selected"" : ""); ?>>May</option>
                                <option value="6" <?php ==($mo == "6" ? "selected="selected"" : ""); ?>>June</option>
                                <option value="7" <?php ==($mo == "7" ? "selected="selected"" : ""); ?>>July</option>
                                <option value="8" <?php ==($mo == "8" ? "selected="selected"" : ""); ?>>August</option>
                                <option value="9" <?php ==($mo == "9" ? "selected="selected"" : ""); ?>>September</option>
                                <option value="10" <?php ==($mo == "10" ? "selected="selected"" : ""); ?>>October</option>
                                <option value="11" <?php ==($mo == "11" ? "selected="selected"" : ""); ?>>November</option>
                                <option value="12" <?php ==($mo == "12" ? "selected="selected"" : ""); ?>>December</option>
                        </select>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

"<?=" is the same as "<?php echo"
Post Reply