Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

opening a javascript link in php -again

Thanks for solving my other post. I managed to solve all the other one except this one


echo ('<a  href="#"
onclick="window.open(\'news/old_news_list.php?month=$j&amp;year='.$i.'\',\'\',\'width=700,height=500\');
return false \" >$thisMonth</a>');


This doesn't open, but again I cannot see where I have gone wrong. Everything looks escaped and sorted. Thanks,


Ross
0
roscoeh23
Asked:
roscoeh23
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
the problem is that the variables $j, $i, and $thisMonth do not get replaced by their values, because you used ' for the string.
the following might work better:

echo ("<a  href=\"#\"
onclick=\"window.open(\'news/old_news_list.php?month=$j&amp;year='.$i.'\',\'\',\'width=700,height=500\\\');
return false \" >$thisMonth</a>");
0
 
RoonaanCommented:
What about using something like this:


$winopen = "window.open('news/old_news_list.php?month=$j&amp;year=$i','',''width=700,height=500);return false;"
echo '<a href=""#" onclick="'.$winOpen.'">'.$thisMonth.'</a>';

Because you where using single quotes, you must notice that your $j, $i and $thisMonth will not be replaced automatically.This will  only happen when using double quotes.

-r-
0
 
roscoeh23Author Commented:
I noticed the mistake $winOpen and $winopen. That looked like it was going to work bur neither do the job.


They both do not open the javascript window which suggests a stntax error or the variable is not getting passed in Roonaan's example.



thanks,


Ross





0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
RoonaanCommented:
Can you do view source from your browser and show us a relevant snippet?

-r-
0
 
roscoeh23Author Commented:
this is with your version of the code

      // Output required months
      for ($j = $monMax; $j >= $monMin; $j--) {
            // Disp month
            $thisMonth = monthname($j);
            
/*      echo("\t\t\t\t<a href=\"news/old_news_list.php?month=$j&amp;year=".$i."\">$thisMonth</a><br />");*/ - THIS IS THE OLD LINE THAT WORKS BUT IT ONLY OPENS IN A BLANK PAGE NOT A POPUP

      
$winopen = "window.open('news/old_news_list.php?month=$j&amp;year=$i','',''width=700,height=500');return false;";
echo '<a href=""#" onclick="'.$winopen.'">'.$thisMonth.'</a>';
      echo "<br />";
            // If not last do a linebreak
            //if ($j != $monMin) { echo("<br />\n"); }
      }
      
      // Finish this year
      echo "\t\t\t</td>\n\t\t\n";
}

echo "\t</tr>\n</table>";

// Clean up
mysql_free_result($result) or die('Free result failed');
0
 
roscoeh23Author Commented:
anyone?
0
 
BuraqueCommented:
can you try this one?
I tested it and it worked:

$text = "<a href='#' onclick=\"window.open('news/old_news_list.php?month=".$j."&year=".$i."','','width=700,height=500'); return false \">".$thisMonth."</a>";
echo $text;
 
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now