Forum Moderators: coopster
You could use PHP to generate the javascript either in a seperate file (using fopen() fwrite() and fclose()), or in the current page exactly the same as you do with html, PHP doesn't care much what type of information you are outputting to the page.
Javascript is usually better kept in seperate files as it saves download times (browser caches the file).You could use PHP to generate the javascript either in a seperate file (using fopen() fwrite() and fclose()), or in the current page exactly the same as you do with html, PHP doesn't care much what type of information you are outputting to the page.
If it is in a seperate file does it matter where it goes in the php file?
Also, I tried adding javascript function right under the db connection and it didn't work, should it be at the top if included in the same file?
You probably just need to break out of php mode?>, and then put it right there, either the script tag including the js file or the function itself.
php really has nothing to do with it.
Open a text editor and insert:
<html>
<head>
<title>page title</title>
<script language="javascript" src="scriptname.js">
</script>
</script>
</head>
<body>
scriptname.js is a txt file containing your jscript code.
Then just do an include "whatever_you_named_the_above_html_file.html";
If you need different page titles, omit the <html><head><title>name</title> part and do the include right after declaring your title in your script.
Like I said, works for me.
Maybe I gave too much detail here. I know I learn best by getting basic instructions that I investigate myself. If I did, my appologies. (mods, just tell me to shut up. LOL).
Later!
IamStang
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title> - </title>
<link href="style.css" rel="stylesheet" type="text/css">
<script>
function displaylyr1(){
nolyr2();
nolyr3();
lyr1.style.display='';
}
function displaylyr2(){
nolyr1();
nolyr3();
lyr2.style.display='';
}
function displaylyr3(){
nolyr1();
nolyr2();
lyr3.style.display='';
}
function nolyr1(){
lyr1.style.display='none';
}
function nolyr2(){
lyr2.style.display='none';
}
function nolyr3(){
lyr3.style.display='none';
}
</script>
</head>
<body>
...
and used the following code in the spot
<div style="display;" id="lyr1">
<p align="center">
<img border="0" src="" width="120" height="60"></p>
</div><div style="display: none;" id="lyr2">
<p align="center">
Hello</p>
</div><div style="display: none;" id="lyr3">
<p align="center">
Goodbye</p>
</div></TD>
</TR>
<TR>
<TD width="98" height="14" bgcolor="#EAEAEA">
<p align="center"><font size="1" face="Verdana">
<a style="text-decoration: none; color: #000000" href="javascript:displaylyr2();void(0);">Link</a></font></TD>
<TD>
<IMG SRC="images/progress-more_10.gif" WIDTH=1 HEIGHT=14 ALT=""></TD>
<TD COLSPAN=3 bgcolor="#797979">
<p align="center"><font size="1" color="#FFFFFF" face="Verdana">
<a href="javascript:displaylyr3()">Click</a></font></TD>
but it still doesn't work?
function displaylyr1(){
nolyr2();
nolyr3();
lyr1.style.display='block';
}
(I tested this with your code in IE 5.5 and it works ok)
You could also probably change your code so you can read it easier:
function display(obj){
obj.style.display='block';
}
function hide(obj)
{
obj.style.display='none';
}
then just call something like display('lyr1') to show it and hide('lyr1') to hide it. It also makes it easier for you to go ahead and add more of them without having to add more functions.
an example:
$movie_genre_java.= "<script language=\"JavaScript\" type=\"text/javascript\">\n";
$movie_genre_java.= "<!--\n";
$movie_genre_java.= "var newGenre = \"\";\n";
$movie_genre_java.= "function genreAdd()\n";
$movie_genre_java.= "{\n";
$movie_genre_java.= "newGenre+='<select name=\"genre[]\" size=\"1\" class=\"menu\">';\n";
$movie_genre_java.= "newGenre+='<option value=\"\" selected>select</option>';\n";
{
//a query to see what genres the user is allowed to list movies on
@mysql_select_db('db');
$query = 'SELECT genre FROM table WHERE genre IS NOT NULL ORDER BY genre ASC';
$result = mysql_query($query) or die ("Error in query: $query " . mysql_error());
$genres = array(); // initialize the genres array
while ($myresult = mysql_fetch_array($result)) // loop through and add each genre to genres array
{
$genres[]= $myresult;
}
foreach ($genres as $genre)
{
// build the options...
$movie_genre_java.= "newGenre+='<option value=\"$genre[0]\"";
$movie_genre_java.= ">$genre[0]</option>';\n";
}
// close the select tags
$movie_genre_java.= "newGenre+='</select><br/>';\n";
$movie_genre_java.= "document.getElementById('genre_container').innerHTML = newGenre;\n";
$movie_genre_java.= "}\n";
$movie_genre_java.= "-->\n";
$movie_genre_java.= "</script>\n"; }
use it as 'echo $movie_genre_java;' where you would normally put the javascript in a HTNL document ;)