Jump to content

[SOLVED] Javscript in PHP


jamesbond110

Recommended Posts

Hi. I have a Javascript menu, and I want to put it in a PHP document. You click the link and more links show up below it.

The external javascript is put in the <head>

 

and then the HTML for the menu is in an external php file and put in with an include. EXAMPLE:

 

<head>

<script src="scripts/nav.js" type="text/javascript"></script>

</head>

 

<div id="masterdiv">
<?php
include 'scripts/nav.php';
?>                               
</div>

 

nav.php looks like

 

<?php
echo '<div class="menutitle" onclick="SwitchMenu("sub1")">Home</div>
<span class="submenu" id="sub1">
<a href="new.html">Newly Added</a><br>
<a href="best.html">Top Rated</a><br>
<a href="editorpick.html">Editor Picks</a><br>
<a href="featured.html">Featured</a><br>
</span>
?>

 

But the script does not work. Live Demo: http://www.tobylands.com

Link to comment
https://forums.phpfreaks.com/topic/109947-solved-javscript-in-php/
Share on other sites

You are not quoting anything correctly. Try:

<?php
echo '<div class="menutitle" onclick="SwitchMenu(\'sub1\')">Home</div>
<span class="submenu" id="sub1">
<a href="new.html">Newly Added</a><br>
<a href="best.html">Top Rated</a><br>
<a href="editorpick.html">Editor Picks</a><br>
<a href="featured.html">Featured</a><br>
</span>';
?>

 

Ken

or just remove the PHP from the equation:

 

<div class="menutitle" onclick="SwitchMenu('sub1')">Home</div>
<span class="submenu" id="sub1">
<a href="new.html">Newly Added</a><br>
<a href="best.html">Top Rated</a><br>
<a href="editorpick.html">Editor Picks</a><br>
<a href="featured.html">Featured</a><br>
</span>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.