Forum Moderators: coopster

Message Too Old, No Replies

Javascript in PHP

         

aanderson

11:24 pm on Apr 23, 2005 (gmt 0)

10+ Year Member



I am creating a base template, nothing fancy, just trying to include the Menu outside of the actual page for easy updating. I am having a problem displaying the drop down menu in the display portion of the browser. However, it displays in the code just fine. All pages are PHP, except the Javascript which is JS.

Layout is:
1 page with the header code of Java.
1 page with the table code of Java
the Actual page which has a php code to include the above
and the actual javascript

Any thoughts? I would post the code but its long. The menu is created from Fireworks, nothing added, nothing taken away.

Arthur

ergophobe

2:12 am on Apr 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Welcome to WebmasterWorld Arthur!


having a problem displaying the drop down menu in the display portion of the browser. However, it displays in the code just fine.

In other words, when browsing it doesn't work, but in view source it looks fine?

If so, it's not a PHP problem. What you need to do is save the source that you are seeing in view source, edit that until it works, and then try to figure out how to make PHP output the working code.

aanderson

7:14 am on Apr 24, 2005 (gmt 0)

10+ Year Member



Did that and uploaded the exact copy, and it came out just fine. All items work and all. Is there a problem in having the javascript code in PHP and having that put into another file?

As it stand the Java code is in a file called menucode.php and is inserted into the header. All the lines are marked with print "--code--\n"; and all the " in the code have a \ to escape the ". Should it all be one long line of code, and each line just have a \n?

Thoughts?

Arthur

IamStang

2:55 pm on Apr 24, 2005 (gmt 0)

10+ Year Member



Not sure if this is what you want for your project, but this is how I would do it in most cases.

Firstly, write the javascript as you would for any webpage. Meaning: no "print" or "\n" in the code. Also, leave off the "<script>" and "</script>" tags. Save that file as "script_name.js".

In your PHP script file add

?>
<html>
<head>
<script language="javascript" src="script_name.js"></script>
</head>
<?
Or if using a header include file, insert
<script language="javascript" src="script_name.js"></script>
between your <head> calls.

Both of the above are assuming that you need to insert your script into the head portion of your page of course.

Hope it helps in some way, however small.
IamStang

mcibor

9:21 pm on Apr 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And if you really need java to be printed by php do it this way:

<?php
//bla bla some code you have
$a = 10;
?>
<script type="text/javascript" language="JavaScript">
<!--
var a = <?php echo $a;?>;
//-->
</script>

You can print the html outside the php, but still processed.

Hope this helps
Michal Cibor

aanderson

9:27 pm on Apr 24, 2005 (gmt 0)

10+ Year Member



Didn't work either. Any thoughts? All I am trying to do is have a horizontal menu, with vertical drop-down mouseover menus. Know of any scripts/programs to creat such a thing? Can you do that with php and not disturb the content?

Thanks,

Arthur

jatar_k

4:45 pm on Apr 25, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you could always use something like this

Horizontal Menus using CSS and Lists [webmasterworld.com]

aanderson

11:24 pm on Apr 25, 2005 (gmt 0)

10+ Year Member



Do you know how you would use a mouseover in that case. I have an image, and would like the menu to appear after the image has been moused over.

Arthur