SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    May 2007
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Open NewWindow Problems

    I've developed a calendar for my site and I want the "event" information to load into a NEW window when the calendar link is clicked. Here is how I have things set up.


    blogs.php
    Code:
    <SCRIPT LANGUAGE="javascript">
    
     function load() {
    var load = window.open('http://www.viglucci.com/nau/cal/view_cal_event.php?date=$date','','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
    }
    
    </SCRIPT>
    calendar.php
    Code:
     <a href='javascript:load()' class='calendarlink'>$currentDay</a>
    These are just snippets of the code. Now when I click on the link inside the calendar a new window pops up, BUT it does not retrieve the information sent by the PHP code. Notice that in my link I have

    view_cal_event.php?date=$date

    Now if I replace "$date" with an actual database date, "2007-12-04" then the code works like a charm.

    My question is: How do I get the code to recognize the variable "$date"?


    You can view the calendar which does NOT work at:
    http://www.viglucci.com/nau/cal/used...test/blogs.php

    You can view a WORKING calendar which just opens the event into a new window, (i.e. target='_blank') at:
    http://www.viglucci.com/nau

    Thanks for your help, I hope I was clear with my problem.

  2. #2
    SitePoint Addict Mirek Komárek's Avatar
    Join Date
    Dec 2006
    Location
    Prague
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Remove target="blank" from second example and add this to head section:


    Code:
    function linked(){
    var lnks=document.getElementById('calendar').getElementsByTagName('a');
    for(var i=0;i<lnks.length;i++){
    lnks[i].onclick=function(){
    window.open(this.href,'','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
    return false;
    }
    }
    }
    window.onload=linked;

  3. #3
    SitePoint Member
    Join Date
    May 2007
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Link doesn't work

    The link doesn't open a new window. Here is the entire code for both my files. Maybe that will help.


    blogs.php
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>My Blogs</title>
    
    <link rel="STYLESHEET" type="text/css" href="stylesheet.css">
    
    <?php
         include "calendar.php";
    ?>
    
    <head>
    <title>Calendar</title>
    
    <SCRIPT LANGUAGE="javascript">
    
    
     function load() {
    var load = window.open('http://www.viglucci.com/nau/cal/view_cal_event.php?date=$date','','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
    }
    
    function linked(){
    var lnks=document.getElementById('calendar').getElementsByTagName('a');
    for(var i=0;i<lnks.length;i++){
    lnks[i].onclick=function(){
    var linked = window.open('http://www.viglucci.com/nau/cal/view_cal_event.php?date=$date','','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
    return false;
    }
    }
    }
    window.onload=linked;
    
    
    </SCRIPT>
    
    
    </head>
    
    <body bgcolor="#ffffff" text="#000000"
          link="#808080" vlink="#000000" alink="#808080">
    
    <?php
    
    if($month==1){ $prevMonth=12; $prevYear=($year-1); } else { $prevMonth=($month-1); $prevYear=$year; }
    		if($month==12) { $nextMonth=1; $nextYear=($year+1);} else { $nextMonth=($month+1); $nextYear=$year; }
    		
    		
    
    
    
         $conn = mysql_pconnect("local","user_name","pw");
    
         $db = mysql_select_db("db");
    
    if (isset($_GET['calendarSetting'])) {
    
         $dateComponents = explode("-",$_GET['calendarSetting']); 
    
         $month = $dateComponents[1];  
         $year = $dateComponents[0];
    	} else {
    
         $dateComponents = getdate(); 
    
         $month = $dateComponents['mon'];  
         $year = $dateComponents['year'];
    
    	}
    
         $query = "SELECT dayofmonth(blogDate) as blogDate FROM myblogs WHERE year(blogDate)='$year' and month (blogDate)='$month'";
    
         $result = mysql_query($query);
    
         while ($row = mysql_fetch_array($result)) { 
              $dateArray[] = $row['blogDate']; 
         }
    $dateArray[]="";
    
         echo build_calendar($month,$year,$dateArray);
    
         if (isset ($_GET['date'])) {
    
              $date = $_GET['date'];
    
         } else {
    
              $date = date("Y-m-d");
    
         }
    
         echo "<p><table width='350'><tr><td><br />Blogs for $date<br />";
    
         $blogQuery = "SELECT blogID, title, content 
                       FROM myblogs WHERE blogDate = '$date'";
    
         $blogResult = mysql_query($blogQuery);
    
         if (mysql_num_rows($blogResult) > 0) {
    
              while (list($blogID,$title,$content) = 
                   mysql_fetch_row($blogResult)) {
    
                   echo "<p>$title<br />$content<br />$blogID</p>";
    
              }
    
         } else {
    
               echo "No blogs available";
    
         }
    
         echo "</td></tr></table></p>";
    
    ?>
    
    </body>
    
    </html>

    calendar.php
    Code:
    <?php
    
    function build_calendar($month,$year,$dateArray) {
    
         // Create array containing abbreviations of days of week.
         $daysOfWeek = array('S','M','T','W','T','F','S');
    
         // What is the first day of the month in question?
         $firstDayOfMonth = mktime(0,0,0,$month,1,$year);
    
         // How many days does this month contain?
         $numberDays = date('t',$firstDayOfMonth);
    
         // Retrieve some information about the first day of the
         // month in question.
         $dateComponents = getdate($firstDayOfMonth);
    
         // What is the name of the month in question?
         $monthName = $dateComponents['month'];
    
         // What is the index value (0-6) of the first day of the
         // month in question.
         $dayOfWeek = $dateComponents['wday'];
    
         // Create the table tag opener and day headers
    
         $calendar = "<table width='180px' class='calendar'>";
         $calendar .= "<caption>$monthName, $year</caption>";
         $calendar .= "<tr>";
    
         // Create the calendar headers
    
         foreach($daysOfWeek as $day) {
              $calendar .= "<th class='header'>$day</th>";
         } 
    
         // Create the rest of the calendar
    
         // Initiate the day counter, starting with the 1st.
    
         $currentDay = 1;
    
         $calendar .= "</tr><tr>";
    
         // The variable $dayOfWeek is used to
         // ensure that the calendar
         // display consists of exactly 7 columns.
    
         if ($dayOfWeek > 0) { 
              $calendar .= "<td colspan='$dayOfWeek'>&nbsp;</td>"; 
         }
    
         while ($currentDay <= $numberDays) {
    
              // Seventh column (Saturday) reached. Start a new row.
    
              if ($dayOfWeek == 7) {
    
                   $dayOfWeek = 0;
                   $calendar .= "</tr><tr>";
    
              }
    
             // Is the $currentDay a member of $dateArray? If so,
             // the day should be linked.
    
             if (in_array($currentDay,$dateArray)) {
    
                $date = "$year-$month-$currentDay";
    
                $calendar .= "<td class='linkedday'>
                           <a href='javascript:linked()' class='calendarlink'>$currentDay</a></td>";
    
              // $currentDay is not a member of $dateArray.
    
              } else {
    
                   $calendar .= "<td class='day'>$currentDay</td>";
    
              }
    
              // Increment counters
     
              $currentDay++;
              $dayOfWeek++;
    
         }
    
         // Complete the row of the last week in month, if necessary
    
         if ($dayOfWeek != 7) { 
         
              $remainingDays = 7 - $dayOfWeek;
              $calendar .= "<td colspan='$remainingDays'>&nbsp;</td>"; 
    
         }
    
         $calendar .= "</table>";
         
    
         return $calendar;
    
    }
    
    ?>

    view_cal_event.php
    Code:
    <html>
    <head>
    <title>Events for <?=$date;?></title>
    
    <body>
    
    <div align="center">
    
    <?php 
    
    $conn = mysql_pconnect("local","user_name","PW");
    
         $db = mysql_select_db("db");
    
    if (isset($_GET['calendarSetting'])) {
    
         $dateComponents = explode("-",$_GET['calendarSetting']); 
    
         $month = $dateComponents[1];  
         $year = $dateComponents[0];
    	} else {
    
         $dateComponents = getdate(); 
    
         $month = $dateComponents['mon'];  
         $year = $dateComponents['year'];
    
    	}
    
         $query = "SELECT dayofmonth(blogDate) as blogDate FROM myblogs WHERE year(blogDate)='$year' and month (blogDate)='$month'";
    
         $result = mysql_query($query);
    
         while ($row = mysql_fetch_array($result)) { 
              $dateArray[] = $row['blogDate']; 
         }
    $dateArray[]="";
    
    
         echo "<p><table width='350'><tr><td><br />Blogs for $date<br />";
    
         $blogQuery = "SELECT blogID, title, content, blogDate 
                       FROM myblogs WHERE blogDate = '$date'";
    
         $blogResult = mysql_query($blogQuery);
    
         if (mysql_num_rows($blogResult) > 0) {
    
              while (list($blogID,$title,$content, $blogDate) = 
                   mysql_fetch_row($blogResult)) {
    
                   echo "<p>$title<br />$content<br />$blogID</p>";
    
              }
    
         } else {
    
               echo "No blogs available";
    
         }
    
         echo "</td></tr></table></p>";
    
    ?>
    
    
      
    </div>
    
    
    </body>
    </HTML>

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What about this?
    Code JavaScript:
    var myUrl = 'http://www.viglucci.com/nau/cal/view_cal_event.php?date='+<?php echo $date?>
    var load = window.open(myUrl,.......
    or maybe
    Code JavaScript:
    var myUrl = "http://www.viglucci.com/nau/cal/view_cal_event.php?date="+"<?php echo $date?>";

    Assume that $date is not empty at that time...

  5. #5
    SitePoint Member
    Join Date
    May 2007
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok so even though this Thread is old, I still want to reply to it because I have figured out the problem which has not only made this script work, but all my other javascript/php problems go away.


    if I use a "forward slash" infront of my "double-quotation marks" then the script recognizes all the variables and opens a new window using the javascript code. Here is what my final code looks like.

    Code:
    for($i=1;$i<=$no_of_days;$i++)
    {	if ($date[$i])
    		{ echo $adj."<td bgcolor='#0099CC' align=center valign=middle><font size='2' face='Times New Roman'><a href=\"javascript:void(0)\"onclick=\"window.open('http://www.viglucci.com/nau/cal/view_cal_event.php?date=$y-$mnum-$i','linkname','height=380, width=400,scrollbars=yes')\">" .$i . "</a><br>"; }
    	else
    		{ echo $adj."<td bgcolor='#E0D8C3' align=center valign=middle><font size='2' face='Times New Roman'>" .$i . "<br>"; 
    }

    I think it has taken me since July to figure this out!! But alas I am new to programming and I have a full time job so being just a hobby I'm prepared for setbacks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •