Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with code modification - link using java within PHP

Status
Not open for further replies.

canajun

Programmer
Sep 28, 2002
57
CA
I have a calendar grid, which has a heading that states the current month:
Code:
 print('<TD class=pc align=middle colSpan=31><a href=add_reservation.php>' . $mnth[$month] . '</TD></TR>');

I want to also display the months before and after, and I have managed so far:

Code:
 print('<TD class=pc align=middle colSpan=31>' . $mnth[$month-2] . '&nbsp&nbsp&nbsp' . $mnth[$month-1] . '&nbsp&nbsp&nbsp<b class=pb>' . $mnth[$month] . '</b>&nbsp&nbsp&nbsp' . $mnth[$month+1] . '&nbsp&nbsp&nbsp' . $mnth[$month+2] . '</TD></TR>');

Within the page, I do have buttons which activate a javascript which displays either the previous, or the following month:
Code:
 <TD align=left colSpan=4><A class=button 
            onmouseover="this.className='button_over'" 
            onfocus="this.className='button_over'" 
            onmouseout="this.className='button'"
            href="javascript:Submit_Action('PREV_MONTH');">&nbsp;[Previous
            Month]&nbsp;</A> </TD>
          <TD align=right colSpan=31><A class=button
            onmouseover="this.className='button_over'"
            onfocus="this.className='button_over'" 
            onmouseout="this.className='button'" 
            href="javascript:Submit_Action('NEXT_MONTH');">&nbsp;[Next 
            Month]&nbsp;</A></TD>

Javascript for the above:

Code:
 function Submit_Action(act)
{
	var yy;
	var mm;
	yy = parseInt(document.frmAvailable.start_cal_year.value);
	mm = parseInt(document.frmAvailable.start_cal_month.value);

	if (act == "NEXT_MONTH")
	{
		if(mm==12)
		{
			mm=1;
			yy=yy+1;
		}
		else
			mm=mm+1;

		document.frmAvailable.start_cal_year.value = yy;
		document.frmAvailable.start_cal_month.value = mm;
		document.frmAvailable.action = "add_reservation.php";
		document.frmAvailable.submit();
	}
	else if(act == "PREV_MONTH")
	{
		if(mm==1)
		{
			mm=12;
			yy=yy-1;
		}
		else
			mm=mm-1;

		document.frmAvailable.start_cal_year.value = yy;
		document.frmAvailable.start_cal_month.value = mm;
		document.frmAvailable.action = "add_reservation.php";
		document.frmAvailable.submit();
	}
}

How can I create a hyperlink from the previous or following months now displayed in the table, so the page goes to that month?

Thanks for any help

 
why don't you just include something like this at the relevant place

Code:
<a href="<?=$_SERVER['PHP_SELF"]?>"?action=nextmonth&curMonth=<?=$month?>">Next Month</a>

and then test inside your php script

Code:
if (isset($_GET['action'])){
  if ($_GET['action'] == 'nextmonth') {
   $displaymonth = ($_GET['curMonth'] == 12) ? 1 : $_GET['curMonth']++;
  }
  elseif($_GET['action'] == 'previousmonth') {
  $displaymonth = ($_GET['curMonth'] == 1) ? 12 : $_GET['curMonth']--;
 }
}
//do something with $displaymonth if it has been set.
 
Ok.. thanks for that, but what I did in the mean time, was jsut add a couple more functions to the javascript.

Probably a little bulkier than someone who knows what they are doing, but it works..

Thanks!
 
and it is not a php solution: and this is a php forum ...
 
I think you misunderstood my initial request.. I was looking for a php solution to using a link to a javascript within the php code.

Sorry to have offended you with my confusion.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top