Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    New to the CF scene
    Join Date
    Apr 2014
    Location
    Puyallup, WA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Calling two seperate JavaScripts at the same time, with one call.

    Hey everyone:

    Good afternoon. First off, thank you for having me, and thank you for any assistance before hand. I have searched these forums over and over and found very useful information, but this time can't find the answer to what I need.

    Here's a real quick summary of what I am trying to do. Just not THAT familiar with how to call it within JavaScript.

    I have a cell within a table on the right side of my webpage. In that cell, I have a randomly generated image that pops up. Currently, when someone clicks on the image, it diverts them away from the website completely. On the left column of the website, I have static images that are set to pop up in a new window / tab, depending on how the users browser is set up. Most of the time though, it's a completely new browser window, which is perfectly fine for me.

    What I would like to do, is combine them *both* on the cell on the right. So when JS randomly shows the image, if someone clicks on it, it will give them a popup / new tab window, instead of completely moving them away from the site. Here's what I have so far. I have the "scripts" and the "calls" in two separate pages. Just combining for optimization here:

    Code for the static pictures on the left bar:

    Code:
    <script type="text/javascript">
    // Popup window code
    function newPopup(url) {
    	popupWindow = window.open(url,'popUpWindow','height=768,width=1024,left=200,top=25,resize=no,location=no,')
    }
    </script>
    
    <tr>
    <td width="149" align="left"><a href="JavaScript:newPopup('/images/leftbar/image.jpg');">
    <img src="/images/leftbar/tn_image.jpg" alt="This pops up the static image in a separate pop-up window or browser tab"/></a></td></tr>
    Code for the randomized picture on the right:

    Code:
    <script type="text/javascript">
    var gallery = new Array();
    gallery[0] = new Array(new Array ("1.gif", "http://www.url.com/"), new Array ("2.gif", "http://www.url.com/"), new Array ("3.jpg", "http://www.url.com/"), new Array ("4.jpg", "http://www.url.com/"));
    <tr>
    <td width="109">&nbsp;</td>
    <td align="right" height="100" width="150"><script language="javascript">pickImageFrom(0);</script></td>
    </tr>
    So in a nuttshell, I would like to have the table cell in the 2nd batch of code, incorporate *both* javascript functions.

    Again, thank you in advance for your assistance. Have a great day!

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,710
    Thanks
    25
    Thanked 660 Times in 659 Posts
    Please check your Code for the randomized picture on the right. it does not seem to work.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #3
    New to the CF scene
    Join Date
    Apr 2014
    Location
    Puyallup, WA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Quote Originally Posted by sunfighter View Post
    Please check your Code for the randomized picture on the right. it does not seem to work.
    Sorry, I was trying to "optimized it for view" so it wasn't so damn long, but forgot a couple lines. So here is the whole code. Thank you for catching that...

    Random Image On Right:
    Code:
    // Write out an IMG tag, using a randomly-chosen image name.
    var choice = pickRandom(ic);
    // -->
    </script>
    
    	<script type="text/javascript">
    	var gallery = new Array();
    	gallery[0] = new Array(
    				new Array ("sunbust_sponsors/thumbnails/1.gif", "http://www.chargerspecialties.com/"),
    				new Array ("sunbust_sponsors/thumbnails/2.gif", "http://www.deltacam.com/"),
    				new Array ("sunbust_sponsors/thumbnails/3.jpg", "http://www.durablock.com/"),
    				new Array ("sunbust_sponsors/thumbnails/4.jpg", "http://www.fiatoftacoma.com/")
    				);
    
    	gallery[1] = new Array(
    				new Array ("sunbust_sponsors/thumbnails/5.gif", "http://www.laysons.com/"),
    				new Array ("sunbust_sponsors/thumbnails/6.jpg", "http://www.tacomadodge.com/"),
    				new Array ("sunbust_sponsors/thumbnails/7.png", "http://www.tacomaautospa.com/"),
    				new Array ("sunbust_sponsors/thumbnails/8.gif", "http://www.theloosewheel.com/")			
    				);
    				
    	gallery[2] = new Array(
    				new Array ("sunbust_sponsors/thumbnails/9.jpeg", "http://www.nwmsrocks.com/"),
    				new Array ("sunbust_sponsors/thumbnails/10.jpg", "http://www.rickyjsplace.com/"),
    				new Array ("sunbust_sponsors/thumbnails/11.jpg", "http://www.rocketresto.com/"),
    				new Array ("sunbust_sponsors/thumbnails/12.jpg", "http://www.statefarm.com/"),
    				new Array ("sunbust_sponsors/thumbnails/13.jpg", "https://plus.google.com/104245004434230903152/")				
    				);
    
    	function pickImageFrom(whichGallery)
    	{
    	var idx = Math.floor(Math.random() * gallery[whichGallery].length);
    
    	document.write('<a href="' + gallery[whichGallery][idx][1] + '"><img src="/images/' + gallery[whichGallery][idx][0] + '"></a>');
    	}
    	</script>

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Code:
    document.write('<a href="' + gallery[whichGallery][idx][1] + '" onclick="newPopup(this.href); return false;"><img src="/images/' + gallery[whichGallery][idx][0] + '"></a>');
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    New to the CF scene
    Join Date
    Apr 2014
    Location
    Puyallup, WA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Result didn't work! :(

    Quote Originally Posted by glenngv View Post
    Code:
    document.write('<a href="' + gallery[whichGallery][idx][1] + '" onclick="newPopup(this.href); return false;"><img src="/images/' + gallery[whichGallery][idx][0] + '"></a>');
    Thanks for the reply.. I tried that, sir. And it did not work. Instead of the actual images, all I see is the following with a broken image between the " signs.

    Code:
      	document.write('');
     
      	document.write('');
     
      	document.write('');
    This is going within a PHP scripted page. I have included the whole page code below, so hopefully that helps as well. My apologies, I didn't know I would need to post the whole page. The 3 lines I added from you are about 3/4 the way down.

    Code:
    <?php include('includes/header.php')?>
    
    <table border="0" width="100%">
    	<tr>
    		<td width="20%">&nbsp;
    		</td>
    		<td width="7%" align="center"><a href="/index.php" title="Mopars Unlimited: Tacoma Chapter Homepage">Home</a></td>
    		<td width="9%" align="center"><a href="/membership/index.php" title="Interested In Joining? Check This Page Out For Information">Membership</a></td>
    		<td width="7%" align="center"><span title="Add one of these events to your calendar. We'll see you there!" style="color: #808000; font-weight: 700; font-style: italic;">Events</span></td>
    		<td width="8%" align="center"><a href="/sunbust/index.php" title="All The Information You Need To Know About The Upcoming Sunbust Event">Sunbust</a></td>
    		<td width="8%" align="center"><a href="/gallery/index.php" title="Image Gallery of Past Events">Gallery</a></td>
    		<td width="8%" align="center"><a href="/classifieds/index.php" title="Looking To Sale or Buy Something? Give This Page A Look">Classifieds</a></td>
    		<td width="6%" align="center"><a href="/about/index.php" title="About Mopars Unlimited: Tacoma Chapter">About</a></td>		
    		<td width="8%" align="center"><a href="/contact/index.php" title="How To Contact Mopars Unlimited: Tacoma Chapter Club Officers">Contact</a></td>		
    		<td width="20%" align="right">Sunbust Event Sponsors</td>
    	</tr>
    </table>
    
    <table border="0" width="100%">
      <tr>
    		<td width="22%">&nbsp;</td>
    	<td width="9%">&nbsp;</td>
    	<td width="10%">&nbsp;</td>
    	<td width="10%">&nbsp;</td>
    	<td width="10%">&nbsp;</td>
    	<td width="8%">&nbsp;</td>		
        <td width="13%">&nbsp;</td>		
    		<td width="18%" align="right" style="font-size:10px">(Clicking these will nagivate you away from our website)</td>
      </tr>
    </table>
    
    <table border="0" width="100%">
    	<tr>
    		<td width="259" valign="top"  class="sponsors" id="sponsors-left">
    		<table border="0">
    			<tr>
    				<td width="149" align="left"><a href="JavaScript:newPopup('/images/leftbar/narrows.jpg');"><img src="/images/leftbar/tn_narrows.jpg" alt="Tacoma Narrows Bridge"/></a></td>
    			</tr>
    			<tr>
    				<td>&nbsp;</td>
    			</tr>
    			<tr>
    				<td align="left"><a href="JavaScript:newPopup('/images/leftbar/tdome.jpg');"><img src="/images/leftbar/tn_tdome.jpg" alt="Tacoma Dome"></a></td>
    			</tr>
    			<tr>
    				<td>&nbsp;</td>
    			</tr>
    			<tr>
    				<td align="left"><a href="JavaScript:newPopup('/images/leftbar/glassmuseum.jpg');"><img src="/images/leftbar/tn_glassmuseum.jpg" alt="Tacoma Glass Museum"></a></td>
    			</tr>
    			<tr>
    				<td>&nbsp;</td>
    			</tr>
    			<tr>
    				<td align="left"><a href="JavaScript:newPopup('/images/leftbar/mtrainier.jpg');"><img src="/images/leftbar/tn_mtrainier.jpg" alt="Mount Rainier"></a></td>
    			</tr>
    		</table>
            </td>
    		<td width="1232" valign="top">
    <?php
    /* $Id: month.php,v 1.95.2.9 2010/08/15 18:54:34 cknudsen Exp $ */
    include_once 'includes/init.php';
    
    //check UAC
    if ( ! access_can_access_function ( ACCESS_MONTH ) || 
      ( ! empty ( $user ) && ! access_user_calendar ( 'view', $user ) )  )
      send_to_preferred_view ();
    
      
    if ( ( $user != $login ) && $is_nonuser_admin )
      load_user_layers ( $user );
    else
    if ( empty ( $user ) )
      load_user_layers ();
    
    $cat_id = getValue ( 'cat_id', '-?[0-9,\-]*', true );
    load_user_categories ();
    
    $next = mktime ( 0, 0, 0, $thismonth + 1, 1, $thisyear );
    $nextYmd = date ( 'Ymd', $next );
    $nextyear = substr ( $nextYmd, 0, 4 );
    $nextmonth = substr ( $nextYmd, 4, 2 );
    
    $prev = mktime ( 0, 0, 0, $thismonth - 1, 1, $thisyear );
    $prevYmd = date ( 'Ymd', $prev );
    $prevyear = substr ( $prevYmd, 0, 4 );
    $prevmonth = substr ( $prevYmd, 4, 2 );
    
    if ( $BOLD_DAYS_IN_YEAR == 'Y' ) {
      $boldDays = true;
      $startdate = mktime ( 0, 0, 0, $prevmonth, 0, $prevyear );
      $enddate = mktime ( 23, 59, 59, $nextmonth + 1, 0, $nextyear );
    } else {
      $boldDays = false;
      $startdate = mktime ( 0, 0, 0, $thismonth, 0, $thisyear );
      $enddate = mktime ( 23, 59, 59, $thismonth + 1, 0, $thisyear );
    }
    
    /* Pre-Load the repeated events for quicker access */
    $repeated_events = read_repeated_events (
      ( ! empty ( $user ) && strlen ( $user ) )
      ? $user : $login, $startdate, $enddate, $cat_id );
    
    /* Pre-load the non-repeating events for quicker access */
    $events = read_events ( ( ! empty ( $user ) && strlen ( $user ) )
      ? $user : $login, $startdate, $enddate, $cat_id );
    
    if ( $DISPLAY_TASKS_IN_GRID == 'Y' )
      /* Pre-load tasks for quicker access */
      $tasks = read_tasks ( ( ! empty ( $user ) && strlen ( $user ) &&
        $is_assistant )
        ? $user : $login, $enddate, $cat_id );
    
    $tableWidth = '100%';
    $monthURL = 'month.php?' . ( ! empty ( $cat_id )
      ? 'cat_id=' . $cat_id . '&amp;' : '' );
    $nextMonth1 = $nextMonth2 = $prevMonth1 = $prevMonth2 = '';
    $printerStr = $smallTasks = $unapprovedStr = '';
    if ( empty ( $DISPLAY_TASKS ) || $DISPLAY_TASKS == 'N' &&
      $DISPLAY_SM_MONTH != 'N' ) {
      $nextMonth1 = display_small_month ( $nextmonth, $nextyear, true, true,
        'nextmonth', $monthURL );
      $prevMonth1 = display_small_month ( $prevmonth, $prevyear, true, true,
        'prevmonth', $monthURL );
    }
    
    if ( $DISPLAY_TASKS == 'Y' && $friendly != 1 ) {
      if (  $DISPLAY_SM_MONTH != 'N' ) {
      $nextMonth2 = display_small_month ( $nextmonth, $nextyear, true, false,
        'nextmonth', $monthURL ) . '<br />';
      $prevMonth2 = display_small_month ( $prevmonth, $prevyear, true, false,
        'prevmonth', $monthURL ) . '<br />';
      } else {
        $nextMonth2 =  $prevMonth2 = '<br /><br /><br /><br />';
      }
      $smallTasks = display_small_tasks ( $cat_id );
      $tableWidth = '80%';
    }
    $eventinfo = ( ! empty ( $eventinfo ) ? $eventinfo : '' );
    $monthStr = display_month ( $thismonth, $thisyear );
    $navStr = display_navigation ( 'month' );
    
    if ( empty ( $friendly ) ) {
      $unapprovedStr = display_unapproved_events (
        ( $is_assistant || $is_nonuser_admin ? $user : $login ) );
      $printerStr = generate_printer_friendly ( 'month.php' );
    }
    $trailerStr = print_trailer ();
    
    $HeadX = generate_refresh_meta ()
      . '<script src="includes/js/weekHover.js" type="text/javascript"></script>';
    
    print_header ( array ( 'js/popups.php/true', 'js/visible.php' ), $HeadX,
    '', false, false, false, false );
    
    echo <<<EOT
        <table border="0" width="100%" cellpadding="1">
          <tr>
            <td id="printarea" valign="top" width="{$tableWidth}" rowspan="2">
              {$prevMonth1}{$nextMonth1}
              {$navStr}
              {$monthStr}
            </td>
            <td valign="top" align="center">
              {$prevMonth2}{$nextMonth2}<div id="minitask">{$smallTasks}</div>
            </td>
          </tr>
        </table>
    
        {$eventinfo}
        {$unapprovedStr}
        {$printerStr}
        {$trailerStr}    
    </td>
           	<td width="259" valign="top" class="sponsors" id="sponsors-right">
    		<table width="100%">
    			<tr>
    			  <td align="right" width="109">&nbsp;</td>
    				<td align="right" height="160" width="150">document.write('<a href="' + gallery[whichGallery][idx][0] + '" onclick="newPopup(this.href); return false;"><img src="/images/' + gallery[whichGallery][idx][0] + '"></a>');</td>
    			</tr>
    			<tr>
    			  <td colspan="2" align="right">&nbsp;</td>
    			</tr>
    			<tr>
    			  <td align="right">&nbsp;</td>
    				<td align="right" height="112">document.write('<a href="' + gallery[whichGallery][idx][2] + '" onclick="newPopup(this.href); return false;"><img src="/images/' + gallery[whichGallery][idx][0] + '"></a>');</td>
    			</tr>
    			<tr>
    			  <td colspan="2" align="right">&nbsp;</td>
    			</tr>
    			<tr>
    			  <td align="right">&nbsp;</td>
    				<td align="right" height="160">document.write('<a href="' + gallery[whichGallery][idx][2] + '" onclick="newPopup(this.href); return false;"><img src="/images/' + gallery[whichGallery][idx][0] + '"></a>');</td>
    			</tr>
                <tr>
    			  <td colspan="2">&nbsp;</td>
    			</tr>
    
    			<tr>
    			  <td colspan="2" align="right" width="150">Mopars Unlimited on Facebook</td>
    			</tr>
                <tr>
                  <td align="right"></td>
               	  <td align="center"><iframe src="//www.facebook.com/plugins/like.php?href=https%3A%2F%2Fwww.facebook.com%2Fpages%2FMopars-Unlimited-of-Tacoma%2F261619924725&amp;layout=button_count&amp;action=like&amp;show_faces=true&amp;share=true&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:130px; height:21px;" allowTransparency="true"></iframe></td>
               </tr>
    			<tr>
    			  <td colspan="2">&nbsp;</td>
    		  </tr>
                <tr>
                  <td align="right"></td>
               	  <td width="150" align="center"><a href="http://www.dmca.com/Protection/Status.aspx?ID=2fa8e23b-1d8a-4be5-bf34-379fc897bb53" title="DMCA"><img src ="http://images.dmca.com/Badges/dmca_protected_sml_120t.png?ID=2fa8e23b-1d8a-4be5-bf34-379fc897bb53"  alt="DMCA.com" /></a></td>
               </tr>
    		</table>
          </td>
    	</tr>
    </table>
    
    EOT;
    ?>
    <table>
      <tr>
        <td>&nbsp;</td>
      </tr>
    </table>
    
    <?php include($_SERVER['DOCUMENT_ROOT'].'/layout/footer.php')?>
    
    <table align="center">
    		<td style="text-align: center; font-size: xx-small;"><?php echo "This page last modified on " . date ("F d Y, h:i A.", getlastmod());?>
            </td>
    </table>
    
    <!-- Begin code tracking for website stats -->
    <script type="text/javascript">
      var _paq = _paq || [];
      _paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
      _paq.push(["setCookieDomain", "*.moparsunlimited.org"]);
      _paq.push(["setDomains", ["*.moparsunlimited.org"]]);
      _paq.push(["trackPageView"]);
      _paq.push(["enableLinkTracking"]);
    
      (function() {
        var u=(("https:" == document.location.protocol) ? "https" : "http") + "://www.moparsunlimited.org/webstats/";
        _paq.push(["setTrackerUrl", u+"piwik.php"]);
        _paq.push(["setSiteId", "1"]);
        var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0]; g.type="text/javascript";
        g.defer=true; g.async=true; g.src=u+"piwik.js"; s.parentNode.insertBefore(g,s);
      })();
    </script>
    <!-- End code tracking for website stats -->
    
    </body>
    </html>

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Why do you have document.write statements without <script> </script> tags?

    Code:
    <td align="right" height="160" width="150">document.write('<a href="' + gallery[whichGallery][idx][0] + '" onclick="newPopup(this.href); return false;"><img src="/images/' + gallery[whichGallery][idx][0] + '"></a>');</td>
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #7
    New to the CF scene
    Join Date
    Apr 2014
    Location
    Puyallup, WA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv View Post
    Why do you have document.write statements without <script> </script> tags?

    Code:
    <td align="right" height="160" width="150">document.write('<a href="' + gallery[whichGallery][idx][0] + '" onclick="newPopup(this.href); return false;"><img src="/images/' + gallery[whichGallery][idx][0] + '"></a>');</td>
    Because I am one huge __________________________ (<-- insert descriptive word here). I overlooked that. I will try that and let you know. Sorry, have been re-writing 100% of this website to get it up and going in a week.

  • #8
    New to the CF scene
    Join Date
    Apr 2014
    Location
    Puyallup, WA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv View Post
    Why do you have document.write statements without <script> </script> tags?

    Code:
    <td align="right" height="160" width="150">document.write('<a href="' + gallery[whichGallery][idx][0] + '" onclick="newPopup(this.href); return false;"><img src="/images/' + gallery[whichGallery][idx][0] + '"></a>');</td>
    I now have it looking like this for each of the 3 lines.

    Code:
    <td align="right" height="160" width="150"><script>document.write('<a href="' + gallery[whichGallery][idx][0] + '" onclick="newPopup(this.href); return false;"><img src="/images/' + gallery[whichGallery][idx][0] + '"></a>');</script></td>
    All it brings up is one huge blank table. If you would like to see what I am talking about, you can look for yourself at Mopars Unlimited: Tacoma Chapter Event Calendar

  • #9
    New to the CF scene
    Join Date
    Apr 2014
    Location
    Puyallup, WA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv View Post
    Why do you have document.write statements without <script> </script> tags?

    Code:
    <td align="right" height="160" width="150">document.write('<a href="' + gallery[whichGallery][idx][0] + '" onclick="newPopup(this.href); return false;"><img src="/images/' + gallery[whichGallery][idx][0] + '"></a>');</td>
    Okay. What I have in there now is this on all 3 lines, and all I get is a blank table.

    Code:
    <td align="right" height="160" width="150"><script>document.write('<a href="' + gallery[whichGallery][idx][0] + '" onclick="newPopup(this.href); return false;"><img src="/images/' + gallery[whichGallery][idx][0] + '"></a>');</script></td>
    If you would like to see what I am talking about, you can look for yourself at test.moparsunlimited.org/webcalendar/month.php

  • #10
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Check the Javascript console for errors. It says "gallery is not defined".
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #11
    New to the CF scene
    Join Date
    Apr 2014
    Location
    Puyallup, WA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv View Post
    Check the Javascript console for errors. It says "gallery is not defined".
    UGH! I have been trying for the last 2 hours to get that to work. No matter what I do, or where I put this damn code, I can't get it to display. I think maybe the reason is because it's a complete PHP page that I am trying to call this in? I don't know. I in fact do have the gallery called (as you can see by doing a pageview on that URL I listed) in the header file. Problem lies, I think, is when the calendar gets called, since that whole thing is written 100% in PHP, it is overriding what I put in before the calendar was called, no?

    I have tried using an echo statement for the javascript declaration, etc., and still can't get the damn thing to work. I even tried putting it in one of the include files the calendar calls, which again, are 100% php, and no success whatsoever.

    Here's the code for the page I am trying to implement it in.
    Code:
    <?php include('includes/header.php')?>
    
    <table border="0" width="100%">
    	<tr>
    		<td width="20%">&nbsp;
    		</td>
    		<td width="7%" align="center"><a href="/index.php" title="Mopars Unlimited: Tacoma Chapter Homepage">Home</a></td>
    		<td width="9%" align="center"><a href="/membership/index.php" title="Interested In Joining? Check This Page Out For Information">Membership</a></td>
    		<td width="7%" align="center"><span title="Add one of these events to your calendar. We'll see you there!" style="color: #808000; font-weight: 700; font-style: italic;">Events</span></td>
    		<td width="8%" align="center"><a href="/sunbust/index.php" title="All The Information You Need To Know About The Upcoming Sunbust Event">Sunbust</a></td>
    		<td width="8%" align="center"><a href="/gallery/index.php" title="Image Gallery of Past Events">Gallery</a></td>
    		<td width="8%" align="center"><a href="/classifieds/index.php" title="Looking To Sale or Buy Something? Give This Page A Look">Classifieds</a></td>
    		<td width="6%" align="center"><a href="/about/index.php" title="About Mopars Unlimited: Tacoma Chapter">About</a></td>		
    		<td width="8%" align="center"><a href="/contact/index.php" title="How To Contact Mopars Unlimited: Tacoma Chapter Club Officers">Contact</a></td>		
    		<td width="20%" align="right">Sunbust Event Sponsors</td>
    	</tr>
    </table>
    
    <table border="0" width="100%">
    	<tr>
    		<td width="20%">&nbsp;</td>
    		<td width="7%">&nbsp;</td>
    		<td width="9%">&nbsp;</td>
    		<td width="7%">&nbsp;</td>
    		<td width="8%">&nbsp;</td>
    		<td width="8%">&nbsp;</td>
    		<td width="8%">&nbsp;</td>
    		<td width="6%">&nbsp;</td>
    		<td width="8%">&nbsp;</td>
    		<td width="20%" align="right" style="font-size:10px">(Clicking these will nagivate you away from our website)</td>
    	</tr>
    </table>
    
    <table border="0" width="100%">
    	<tr>
    		<td width="259" valign="top"  class="sponsors" id="sponsors-left">
    		<table border="0">
    			<tr>
    				<td width="149" align="left"><a href="JavaScript:newPopup('/images/leftbar/narrows.jpg');"><img src="/images/leftbar/tn_narrows.jpg" alt="Tacoma Narrows Bridge"/></a></td>
    			</tr>
    			<tr>
    				<td>&nbsp;</td>
    			</tr>
    			<tr>
    				<td align="left"><a href="JavaScript:newPopup('/images/leftbar/tdome.jpg');"><img src="/images/leftbar/tn_tdome.jpg" alt="Tacoma Dome"></a></td>
    			</tr>
    			<tr>
    				<td>&nbsp;</td>
    			</tr>
    			<tr>
    				<td align="left"><a href="JavaScript:newPopup('/images/leftbar/glassmuseum.jpg');"><img src="/images/leftbar/tn_glassmuseum.jpg" alt="Tacoma Glass Museum"></a></td>
    			</tr>
    			<tr>
    				<td>&nbsp;</td>
    			</tr>
    			<tr>
    				<td align="left"><a href="JavaScript:newPopup('/images/leftbar/mtrainier.jpg');"><img src="/images/leftbar/tn_mtrainier.jpg" alt="Mount Rainier"></a></td>
    			</tr>
    		</table>
            </td>
    		<td width="1232" valign="top">
    <!-- START OF CALENDAR -->
    <?php
    /* $Id: month.php,v 1.95.2.9 2010/08/15 18:54:34 cknudsen Exp $ */
    include_once 'includes/init.php';
    
    //check UAC
    if ( ! access_can_access_function ( ACCESS_MONTH ) || 
      ( ! empty ( $user ) && ! access_user_calendar ( 'view', $user ) )  )
      send_to_preferred_view ();
    
      
    if ( ( $user != $login ) && $is_nonuser_admin )
      load_user_layers ( $user );
    else
    if ( empty ( $user ) )
      load_user_layers ();
    
    $cat_id = getValue ( 'cat_id', '-?[0-9,\-]*', true );
    load_user_categories ();
    
    $next = mktime ( 0, 0, 0, $thismonth + 1, 1, $thisyear );
    $nextYmd = date ( 'Ymd', $next );
    $nextyear = substr ( $nextYmd, 0, 4 );
    $nextmonth = substr ( $nextYmd, 4, 2 );
    
    $prev = mktime ( 0, 0, 0, $thismonth - 1, 1, $thisyear );
    $prevYmd = date ( 'Ymd', $prev );
    $prevyear = substr ( $prevYmd, 0, 4 );
    $prevmonth = substr ( $prevYmd, 4, 2 );
    
    if ( $BOLD_DAYS_IN_YEAR == 'Y' ) {
      $boldDays = true;
      $startdate = mktime ( 0, 0, 0, $prevmonth, 0, $prevyear );
      $enddate = mktime ( 23, 59, 59, $nextmonth + 1, 0, $nextyear );
    } else {
      $boldDays = false;
      $startdate = mktime ( 0, 0, 0, $thismonth, 0, $thisyear );
      $enddate = mktime ( 23, 59, 59, $thismonth + 1, 0, $thisyear );
    }
    
    /* Pre-Load the repeated events for quicker access */
    $repeated_events = read_repeated_events (
      ( ! empty ( $user ) && strlen ( $user ) )
      ? $user : $login, $startdate, $enddate, $cat_id );
    
    /* Pre-load the non-repeating events for quicker access */
    $events = read_events ( ( ! empty ( $user ) && strlen ( $user ) )
      ? $user : $login, $startdate, $enddate, $cat_id );
    
    if ( $DISPLAY_TASKS_IN_GRID == 'Y' )
      /* Pre-load tasks for quicker access */
      $tasks = read_tasks ( ( ! empty ( $user ) && strlen ( $user ) &&
        $is_assistant )
        ? $user : $login, $enddate, $cat_id );
    
    $tableWidth = '100%';
    $monthURL = 'month.php?' . ( ! empty ( $cat_id )
      ? 'cat_id=' . $cat_id . '&amp;' : '' );
    $nextMonth1 = $nextMonth2 = $prevMonth1 = $prevMonth2 = '';
    $printerStr = $smallTasks = $unapprovedStr = '';
    if ( empty ( $DISPLAY_TASKS ) || $DISPLAY_TASKS == 'N' &&
      $DISPLAY_SM_MONTH != 'N' ) {
      $nextMonth1 = display_small_month ( $nextmonth, $nextyear, true, true,
        'nextmonth', $monthURL );
      $prevMonth1 = display_small_month ( $prevmonth, $prevyear, true, true,
        'prevmonth', $monthURL );
    }
    
    if ( $DISPLAY_TASKS == 'Y' && $friendly != 1 ) {
      if (  $DISPLAY_SM_MONTH != 'N' ) {
      $nextMonth2 = display_small_month ( $nextmonth, $nextyear, true, false,
        'nextmonth', $monthURL ) . '<br />';
      $prevMonth2 = display_small_month ( $prevmonth, $prevyear, true, false,
        'prevmonth', $monthURL ) . '<br />';
      } else {
        $nextMonth2 =  $prevMonth2 = '<br /><br /><br /><br />';
      }
      $smallTasks = display_small_tasks ( $cat_id );
      $tableWidth = '80%';
    }
    $eventinfo = ( ! empty ( $eventinfo ) ? $eventinfo : '' );
    $monthStr = display_month ( $thismonth, $thisyear );
    $navStr = display_navigation ( 'month' );
    
    if ( empty ( $friendly ) ) {
      $unapprovedStr = display_unapproved_events (
        ( $is_assistant || $is_nonuser_admin ? $user : $login ) );
      $printerStr = generate_printer_friendly ( 'month.php' );
    }
    $trailerStr = print_trailer ();
    
    $HeadX = generate_refresh_meta ()
      . '<script src="includes/js/weekHover.js" type="text/javascript"></script>';
    
    print_header ( array ( 'js/popups.php/true', 'js/visible.php' ), $HeadX,
    '', false, false, false, false );
    
    echo <<<EOT
        <table border="0" width="100%" cellpadding="1">
          <tr>
            <td id="printarea" valign="top" width="{$tableWidth}" rowspan="2">
              {$prevMonth1}{$nextMonth1}
              {$navStr}
              {$monthStr}
            </td>
            <td valign="top" align="center">
              {$prevMonth2}{$nextMonth2}<div id="minitask">{$smallTasks}</div>
            </td>
          </tr>
        </table>
    
        {$eventinfo}
        {$unapprovedStr}
        {$printerStr}
        {$trailerStr}    
    </td>
           	<td width="259" valign="top" class="sponsors" id="sponsors-right">
    		<table width="100%">
    			<tr>
    			  <td align="right" width="109">&nbsp;</td>
    				<td align="right" height="160" width="150"><script language="JavaScript">document.write('<a href="' + gallery[whichGallery][idx][0] + '" onclick="newPopup(this.href); return false;"><img src="/images/' + gallery[whichGallery][idx][0] + '"></a>');</script></td>
    			</tr>
    			<tr>
    			  <td colspan="2" align="right">&nbsp;</td>
    			</tr>
    			<tr>
    			  <td align="right">&nbsp;</td>
    				<td align="right" height="160"><script language="JavaScript">document.write('<a href="' + gallery[whichGallery][idx][1] + '" onclick="newPopup(this.href); return false;"><img src="/images/' + gallery[whichGallery][idx][0] + '"></a>');</script></td>
    			</tr>
    			<tr>
    			  <td colspan="2" align="right">&nbsp;</td>
    			</tr>
    			<tr>
    			  <td align="right">&nbsp;</td>
    				<td align="right" height="160"><script language="JavaScript">document.write('<a href="' + gallery[whichGallery][idx][2] + '" onclick="newPopup(this.href); return false;"><img src="/images/' + gallery[whichGallery][idx][0] + '"></a>');</script></td>
    			</tr>
                <tr>
    			  <td colspan="2">&nbsp;</td>
    			</tr>
    
    			<tr>
    			  <td colspan="2" align="right" width="150">Mopars Unlimited on Facebook</td>
    			</tr>
                <tr>
                  <td align="right"></td>
               	  <td align="center"><iframe src="//www.facebook.com/plugins/like.php?href=https%3A%2F%2Fwww.facebook.com%2Fpages%2FMopars-Unlimited-of-Tacoma%2F261619924725&amp;layout=button_count&amp;action=like&amp;show_faces=true&amp;share=true&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:130px; height:21px;" allowTransparency="true"></iframe></td>
               </tr>
    			<tr>
    			  <td colspan="2">&nbsp;</td>
    		  </tr>
                <tr>
                  <td align="right"></td>
               	  <td width="150" align="center"><a href="http://www.dmca.com/Protection/Status.aspx?ID=2fa8e23b-1d8a-4be5-bf34-379fc897bb53" title="DMCA"><img src ="http://images.dmca.com/Badges/dmca_protected_sml_120t.png?ID=2fa8e23b-1d8a-4be5-bf34-379fc897bb53"  alt="DMCA.com" /></a></td>
               </tr>
    		</table>
          </td>
    	</tr>
    </table>
    
    EOT;
    ?>
    <!-- END OF CALENDAR -->
    
    <table>
      <tr>
        <td>&nbsp;</td>
      </tr>
    </table>
    
    <?php include($_SERVER['DOCUMENT_ROOT'].'/layout/footer.php')?>
    
    <table align="center">
    		<td style="text-align: center; font-size: xx-small;"><?php echo "This page last modified on " . date ("F d Y, h:i A.", getlastmod());?>
            </td>
    </table>
    
    <!-- Begin code tracking for website stats -->
    <script type="text/javascript">
      var _paq = _paq || [];
      _paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
      _paq.push(["setCookieDomain", "*.moparsunlimited.org"]);
      _paq.push(["setDomains", ["*.moparsunlimited.org"]]);
      _paq.push(["trackPageView"]);
      _paq.push(["enableLinkTracking"]);
    
      (function() {
        var u=(("https:" == document.location.protocol) ? "https" : "http") + "://www.moparsunlimited.org/webstats/";
        _paq.push(["setTrackerUrl", u+"piwik.php"]);
        _paq.push(["setSiteId", "1"]);
        var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0]; g.type="text/javascript";
        g.defer=true; g.async=true; g.src=u+"piwik.js"; s.parentNode.insertBefore(g,s);
      })();
    </script>
    <!-- End code tracking for website stats -->
    
    </body>
    </html>

  • #12
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Now I'm seeing "whichGallery not defined" in this line:

    Code:
    <td align="right" height="160" width="150"><script language="JavaScript">document.write('<a href="' + gallery[whichGallery][idx][0] + '" onclick="newPopup(this.href); return false;"><img src="/images/' + gallery[whichGallery][idx][0] + '"></a>');</script></td>
    I can also see that "idx" is undefined too.

    I think this is what you need:
    Code:
    function pickImageFrom(whichGallery) {
    	var idx = Math.floor(Math.random() * gallery[whichGallery].length);
    	document.write('<a href="' + gallery[whichGallery][idx][1] + '" onclick="newPopup(this.href); return false;"><img src="/images/' + gallery[whichGallery][idx][0] + '"></a>');
    }
    Code:
    <td align="right" height="160" width="150"><script type="text/javascript">pickImageFrom(0);</script></td>
    But note that it's not recommended to use document.write to generate dynamic content. Generally, you should use innerHTML instead.

    But in your case, I highly recommend you to generate the links in PHP instead of Javascript.
    PHP Code:
    <?php
    $gallery 
    = array(
        array(
            array(
    "sunbust_sponsors/thumbnails/1.gif""http://www.chargerspecialties.com/"),
            array(
    "sunbust_sponsors/thumbnails/2.gif""http://www.deltacam.com/"),
            array(
    "sunbust_sponsors/thumbnails/3.jpg""http://www.durablock.com/"),
            array(
    "sunbust_sponsors/thumbnails/4.jpg""http://www.fiatoftacoma.com/"), 
        ),
        array(
           ...
        ),
        ...
    );

    function 
    pickImageFrom($whichGallery)
    {
        
    $idx rand(0count($gallery[$whichGallery]) - 1);
        echo 
    '<a href="' $gallery[$whichGallery][$idx][1] . '" onclick="newPopup(this.href); return false;"><img src="/images/' $gallery[$whichGallery][$idx][0] . '"></a>';
    }

    ...

    <
    td align="right" height="160" width="150"><?php echo pickImageFrom(0); ?></td>
    I haven't done PHP in a long while, so the syntax might be wrong. But you'll get the idea.
    Last edited by glenngv; 04-10-2014 at 03:21 AM.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #13
    New to the CF scene
    Join Date
    Apr 2014
    Location
    Puyallup, WA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv View Post
    Now I'm seeing "whichGallery not defined" in this line:

    Code:
    <td align="right" height="160" width="150"><script language="JavaScript">document.write('<a href="' + gallery[whichGallery][idx][0] + '" onclick="newPopup(this.href); return false;"><img src="/images/' + gallery[whichGallery][idx][0] + '"></a>');</script></td>
    I can also see that "idx" is undefined too.

    I think this is what you need:
    Code:
    function pickImageFrom(whichGallery) {
    	var idx = Math.floor(Math.random() * gallery[whichGallery].length);
    	document.write('<a href="' + gallery[whichGallery][idx][1] + '" onclick="newPopup(this.href); return false;"><img src="/images/' + gallery[whichGallery][idx][0] + '"></a>');
    }
    Code:
    <td align="right" height="160" width="150"><script type="text/javascript">pickImageFrom(0);</script></td>
    But note that it's not recommended to use document.write to generate dynamic content. Generally, you should use innerHTML instead.

    But in your case, I highly recommend you to generate the links in PHP instead of Javascript.
    PHP Code:
    <?php
    $gallery 
    = array(
        array(
            array(
    "sunbust_sponsors/thumbnails/1.gif""http://www.chargerspecialties.com/"),
            array(
    "sunbust_sponsors/thumbnails/2.gif""http://www.deltacam.com/"),
            array(
    "sunbust_sponsors/thumbnails/3.jpg""http://www.durablock.com/"),
            array(
    "sunbust_sponsors/thumbnails/4.jpg""http://www.fiatoftacoma.com/"), 
        ),
        array(
           ...
        ),
        ...
    );

    function 
    pickImageFrom($whichGallery)
    {
        
    $idx rand(0count($gallery[$whichGallery]) - 1);
        echo 
    '<a href="' $gallery[$whichGallery][$idx][1] . '" onclick="newPopup(this.href); return false;"><img src="/images/' $gallery[$whichGallery][$idx][0] . '"></a>';
    }

    ...

    <
    td align="right" height="160" width="150"><?php echo pickImageFrom(0); ?></td>
    I haven't done PHP in a long while, so the syntax might be wrong. But you'll get the idea.
    I give up! No matter what I do, I can't get this _________________ (<-- insert word(s) here) thing to work. This is the code I have, and I get errors stating that now gallery, whichgallery, and idx are all undefined.
    Code:
    echo <<<EOT
        <table border="0" width="100%" cellpadding="1">
          <tr>
            <td id="printarea" valign="top" width="{$tableWidth}" rowspan="2">
              {$prevMonth1}{$nextMonth1}
              {$navStr}
              {$monthStr}
            </td>
            <td valign="top" align="center">
              {$prevMonth2}{$nextMonth2}<div id="minitask">{$smallTasks}</div>
            </td>
          </tr>
        </table>
    
        {$eventinfo}
        {$unapprovedStr}
        {$printerStr}
        {$trailerStr}    
    </td>
    
    $gallery = array(
        array(
            array("/images/sunbust_sponsors/thumbnails/1.gif", "http://www.chargerspecialties.com/"),
            array("/images/sunbust_sponsors/thumbnails/2.gif", "http://www.deltacam.com/"),
            array("/images/sunbust_sponsors/thumbnails/3.jpg", "http://www.durablock.com/"),
            array("/images/sunbust_sponsors/thumbnails/4.jpg", "http://www.fiatoftacoma.com/"), 
        ),
        array(
            array("/images/sunbust_sponsors/thumbnails/1.gif", "http://www.chargerspecialties.com/"),
            array("/images/sunbust_sponsors/thumbnails/2.gif", "http://www.deltacam.com/"),
            array("/images/sunbust_sponsors/thumbnails/3.jpg", "http://www.durablock.com/"),
            array("/images/sunbust_sponsors/thumbnails/4.jpg", "http://www.fiatoftacoma.com/"), 
        ),
            array("/images/sunbust_sponsors/thumbnails/1.gif", "http://www.chargerspecialties.com/"),
            array("/images/sunbust_sponsors/thumbnails/2.gif", "http://www.deltacam.com/"),
            array("/images/sunbust_sponsors/thumbnails/3.jpg", "http://www.durablock.com/"),
            array("/images/sunbust_sponsors/thumbnails/4.jpg", "http://www.fiatoftacoma.com/"), 
    );
    
    function pickImageFrom($whichGallery)
    {
        $idx = rand(0, count($gallery[$whichGallery]) - 1);
        echo '<a href="' . $gallery[$whichGallery][$idx][1] . '" onclick="newPopup(this.href); return false;"><img src="/images/' . $gallery[$whichGallery][$idx][0] . '"></a>';
    }
    
    
           	<td width="259" valign="top" class="sponsors" id="sponsors-right">
    		<table width="100%">
    			<tr>
    			  <td align="right" width="109">&nbsp;</td>
    			<td align="right" height="160" width="150"><?php echo pickImageFrom(0); ?></td>
    			</tr>
    			<tr>
    			  <td colspan="2" align="right">&nbsp;</td>
    			</tr>
    			<tr>
    			  <td align="right">&nbsp;</td>
    				<td align="right" height="112"><a href="http://www.tacomadodge.com"><img src="/images/sunbust_sponsors/thumbnails/6.jpg" alt="Tacoma Dodge" width="150"/></a></td>
    			</tr>
    			<tr>
    			  <td colspan="2" align="right">&nbsp;</td>
    			</tr>
    			<tr>
    			  <td align="right">&nbsp;</td>
    				<td align="right" height="160"><a href="http://www.tacomadodge.com"><img src="/images/sunbust_sponsors/thumbnails/5.gif" alt="Layson's Restoration" width="150"/></a></td>
    			</tr>
                <tr>
    			  <td colspan="2">&nbsp;</td>
    			</tr>
    
    			<tr>
    			  <td colspan="2" align="right" width="150">Mopars Unlimited on Facebook</td>
    			</tr>
                <tr>
                  <td align="right"></td>
               	  <td align="center"><iframe src="//www.facebook.com/plugins/like.php?href=https%3A%2F%2Fwww.facebook.com%2Fpages%2FMopars-Unlimited-of-Tacoma%2F261619924725&amp;layout=button_count&amp;action=like&amp;show_faces=true&amp;share=true&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:130px; height:21px;" allowTransparency="true"></iframe></td>
               </tr>
    		</table>
          </td>
    	</tr>
    </table>
    
    EOT;
    ?>
    And with this line:
    Code:
    <td align="right" height="160" width="150"><?php echo pickImageFrom(0); ?></td>
    it *really* messes with the rest of the file. It throws up a syntax error on line 274 which is:

    Code:
    EOT;?>
    Since there's still PHP going on after this call, it sees the "?>" in the <td> calland cancels the rest of the PHP in the file.

    This OBVIOUSLY wasn't meant for me to get to work! :(

  • #14
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    You should know PHP better than me as you are using a heredoc syntax which I have never used.

    But here's my stab at it:

    Take out the $gallery and pickImageFrom() declaration out of the "echo <<<EOT" block. As I've read about heredoc, it does not allow directly calling a function inside it. I researched and found this Using functions/expressions in HEREDOC strings technique which I applied here.

    PHP Code:
    $gallery = array(
       
    //...your array declaration here
    );

    function 
    pickImageFrom($whichGallery)
        
    $idx rand(0count($gallery[$whichGallery]) - 1);
        echo 
    '<a href="' $gallery[$whichGallery][$idx][1] . '" onclick="newPopup(this.href); return false;"><img src="/images/' $gallery[$whichGallery][$idx][0] . '"></a>';
    }

    $pickImageFrom_func 'pickImageFrom';
    ...

    echo <<<EOT
    ...
    <td align="right" height="160" width="150"><
    {$pickImageFrom_func(0)}</td>
    ...
    EOT;
    ?> 
    As I mentioned earlier, I don't know much PHP, so there must be some syntax error or other glaring errors. If this does not work, I suggest to ask a moderator to move this thread to the PHP forum.
    Last edited by glenngv; 04-11-2014 at 08:49 AM.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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