2 Replies - 994 Views - Last Post: 16 October 2011 - 08:02 AM Rate Topic: -----

#1 rpgmaker  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 224
  • Joined: 02-October 11

Java script works on its own page but not with another page

Posted 16 October 2011 - 07:22 AM

Hello members i have a java script / php problem .
I have a page lets call it page 1 . The java script and php works on page 1 ( with out html or body tags )
It does what i want . So i made my own template and thought the code works so now i can copy the full code onto the center of my template. I put it onto my php page and it showed the results so the php side was working but the java script stopped working ?? I then thought what about a php inculde ? seen has the java script is working on page 1 on its own . So i did a inculde and still the java script stopped working.

I have tried to avoid this for around a year now i have been working on other projects because i can't get my head around it and would love to find the problem.

So here is page 1 were the code / script works on


<?php

include "include/session.php";   

include "config.php";   


$hp = mysql_query("SELECT * FROM user_pokemon WHERE username='".$_SESSION['username']."'")
					or die("Failed to fetch your hp.");
$hppp  = mysql_fetch_array($hp);

?>







<?php
	if (isset($_POST['Changeactive'])) {
		$_SESSION['current_pokemon'] = $_POST['Changeactive'];
	}
?>


	<table width="686" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="white">
		<p style="text-align:left;margin-left:5px;">to change active pokemon simply click the slot number</p>
<form name="ChangeSubmit" id="ChangeSubmit" method="post" action="">	
<?php
	function bgColor($var) {
		if ($_SESSION['current_pokemon'] == $var) {
			return 'bgcolor="#FF9900"';
		} else {
			return 'bgcolor="#333333"';
		}
	}
			
	function pokmessage($var) {
		if ($_SESSION['current_pokemon'] == $var) {
			return 'ACTIVE';
		} else {
			return '<a href="Javascript:ChangeActive(\''.$var.'\');">'.$var.'</a>';
		}
	}
?>
<input type="hidden" name="Changeactive" id="Changeactive" value=""/>
</form>
	<tr bordercolor="black">
<?php for ($x=1;$x<7;$x++) { ?>
		<td <?php echo bgColor($x); ?>>
			<center class="style7">
				<span class="style7"><b>
					<?php 
						if (isset($pokemon->{"pok" . $x}['pokeNAME'])) {
							echo pokmessage($x);
						} else {
							echo $x;
						}
					
			
					?>
				</b></span>
			</center>
		</td>
<?php } ?>		
	</tr>
			   
			   
     <tr bordercolor="black">

<?php 
	for ($x=1;$x<=6;$x++) {
		if (isset($pokemon->{"pok" . $x}['pokeNAME'])) { ?>
	   <th scope="row" align="center" width="70px">
			<p><img src="/images/pokemon/<?php echo $pokemon->{"pok" . $x}['pokePIC']; ?>" width="32" height="32">
			<p><?php echo $pokemon->{"pok" . $x}['pokeNAME'].'<br/>';  echo 'Level:'.$pokemon->levels[($x-1)]; ?> </p>
			 <span class="style2">Hp:
			 <?php	include_once "hp".$x.".php"; ?>
			
			
			
			 
			 
			 
		    </span>		 </th>
	<?php } else { ?>
			<th scope="row" align="center" width="70px">
			<p>Empty Slot</p>
			</th>
	<?php }
	}
?>
      </tr>

</table>
			   
<script language="Javascript" type="text/javascript">
	function ChangeActive(VAR) {
		document.getElementById("Changeactive").value = VAR;
		ChangeSubmit.submit()
	}
</script>








I can re name the page mickey mouse and it would still work ....

So now i try and put it onto my html template / php page ..

<html>
<head>

              <?
/**
 * Main.php
 *
 */
include("include/session.php");



include "config.php";   


?>
    <title>De beste no rules maffia game ooit</title>
    <link rel="stylesheet" type="text/css" href="scripts/fancybox/jquery.fancybox.css"/>
    <link rel="stylesheet" type="text/css" href="layouts/031/style.css"/>
    <link rel="stylesheet" type="text/css" href="game.css"/>
    <style type="text/css">
      .vip { background: url('images/icons/set_2/game_vip.png') right center no-repeat; padding-right: 14px; }
      .level0 { color: red !important; text-decoration: line-through !important; }
      .level1 { }
      .level2 { color: #a67a46 !important; }
      .level3 { color: #F8AC27 !important; }
      .level4 { color: #3B14B7 !important; }
      .level5 { color: #BE0909 !important; }
      .level6 { color: #6C0882 !important; background: url('images/icons/set_1/game_owner.png') right center no-repeat; padding-right: 20px; }
      h1.gamenaam { font-size: 28px !important; color: #F5EBEB !important; }    .style1 {color: #FF0000}
    </style>
    <base />
    <link rel="shortcut icon" type="image/png" href="favicon.png"/>
    <meta name="keywords" content="maffia spel, mmorpg, spel, online games multiplayer, online rpg, maffia spellen, crime games, maffia, online spel"/>
    <meta name="description" content="Speel gratis mee in de onderwereld van een echte maffioso en meld je nu gratis aan op de beste crime spel online."/>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-15"/>
    <script type="text/javascript" src="scripts/fancybox/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="scripts/fancybox/jquery.easing.1.3.js"></script>
    <script type="text/javascript" src="scripts/fancybox/jquery.fancybox-1.2.1.pack.js"></script>
    <script type="text/javascript">
      if (top.location != location) {
        top.location.href = document.location.href;
      }    
    </script>
    <script type="text/javascript">
      var jQ = jQuery.noConflict();
      jQ(document).ready(function() {
        jQ("a.fancy").fancybox({
          'zoomOpacity': true,
          'overlayShow': false,
          'zoomSpeedIn': 500,
          'zoomSpeedOut': 500
        });
      });
    </script>
    <script type="text/javascript" src="scripts/ajax/prototype.js"></script>
        <script type="text/javascript" src="scripts/cufon/cufon-yui.js"></script>
</head>
  <body>
    <script type="text/javascript" src="scripts/tooltip/tooltip.js"></script>
    <div id="top_menu">
      <div class="left">
        <a href="index.html">Startseite</a>
        <a href="contact.html">Kontakt</a>
        <a href="crew.html">Team</a>
        <a href="info/1/prijzen-r7.html">Prijzen R7</a>
      </div>
    </div>
    <div id="top_header">
      <div id="site_header" style="background: url(uploads/game_headers/109422.png) no-repeat;">
        <h1 class="gamenaam"></h1>
        <div class="login">
          <form method="post" action="http://www.sicilian-mafia.nl/login">
            <img src="images/icons/set_2/status_offline.png"/>
            <input type="text" name="username" maxlength="15"/>
            &nbsp;
            <img src="images/icons/set_2/password.png"/>
            <input type="password" name="password">
            &nbsp;
            <input type="submit" name="submit" class="" value="Anmelden"/>
          </form>
        </div>
      </div>
    </div>
    <div id="container">
      <div id="left_menu">
        <div class="top">&nbsp;</div>
        <div class="items">
          <ul><li class="t">Pokemon Toxic Rpg</li><li><a href="register.html">Registrieren</a></li>
<li><a href="manual.html">Anleitung</a></li>
<li><a href="maffia-story.html">Die Geschichte</a></li><li><a href="login/lost-password.html">Passwort vergessen?</a></li>
<li><a href="info/5/linkpartners.html">Linkpartners</a></li></ul>
          <ul class="screenshots">
            <li class="t">Pokemon in game </li>
            <li><a class="fancy" rel="group" href="uploads/game_screens/109422-big1.png"><img alt="" src="pokemon/Gold Enti.png" width="63" height="64"/><img alt="" src="pokemon/diamond_ray.png" width="80" height="80"/></a><a class="fancy" rel="group" href="uploads/game_screens/109422-big3.png"><img alt="" src="pokemon/245M.gif" width="69" height="70"/></a><a class="fancy" rel="group" href="uploads/game_screens/109422-big1.png"><img alt="" src="pokemon/243M.gif" width="73" height="67"/></a><a class="fancy" rel="group" href="uploads/game_screens/109422-big3.png"></a></li>
<li></li>
<li></li>
</ul>
        </div>
        <div class="bottom">&nbsp;</div>
      </div>
      <div id="main_content">
<div class="content_block">
  <div class="content_inner">
    <h1>Willkommen!</h1>
<p>&nbsp;</p>
<table class="content_table">
  <tr>
    <td colspan="2" width="70%" class="tsub" style="vertical-align: top"> HET IS ZO VER DAT WIL JE NIET MISSEN </td>
    <td width="30%" class="tsub" style="text-align: right; font-weight: normal"><img style="margin-bottom:-4px" src="images/icons/set_2/date.png" alt="" />&nbsp;03/10/2011 19:47 </td>
  </tr>
  <tr>
    <td width="20%" class="tcell" align="center" style="vertical-align: top"><img src="uploads/user_avatars/682020.gif"/><br/>
      <a href="member/Peggy.html" class="level6 vip style1">Shadow</a> </td>
    <td colspan="2" class="tcell" style="vertical-align: top"><strong>De nieuwe RONDE 7 is van start gegaan.<br />
      Bereid je voor…<br />
      Het wordt weer spannend…<br />
      En het is zo ver…EINDELIJK</strong> <br />
      <font style="color: #A00000">DE NIEUWE RONDE IS BEGONNEN!!! Op 01-10-2011 </font><br />
      <br />
      <strong>Sicilian-Mafia is back met een NIEUWE RONDE en dat wil je niet missen. Nog beter, nog gezelliger, nog meer concurrenten en nog spannender.<br />
        <br />
        Met veel nieuwe leden maar ook met onze heel trouwe leden en heel veel unieke acties. Dus kom ook deze ronde weer gezellig mee spelen.<br />
        Echte prijzen, echte tegenstanders en echte maffia sfeer… We zien je zo terug op SICILIAN-MAFIA.NL.....</strong><br />
      <br />
      OF MELD JE METEEN AAN!: <a target="_blank" href="register.html">http://www.sicilian-mafia.nl/register</a><strong> --&gt; helemaal GRATIS!!!</strong> </td>
  </tr>
</table>
<p><span style="color: #a9aeef;"><a href="index.html"><br /><br /></a></span></p>
<table style="border-collapse: collapse; width: 100%; height: 31px;" border="0" cellspacing="0" cellpadding="0" bordercolor="#111111">
<tbody>
<tr>
<td width="50%" height="19">&nbsp;</td>
<td width="50%" height="19">
<p>&nbsp;</p>
</td>
</tr>
<tr>
<td width="50%" height="19">
<p align="center"><a href="manual.html"> <img src="../www.hotsex-online.nl/button_introductie_01.jpg" border="0" alt="" width="190" height="50" /></a></p>
</td>
<td width="50%" height="19">
<p align="center"><a href="register.html"> <img src="../www.hotsex-online.nl/button_aanmelden_01.jpg" border="0" alt="" width="190" height="50" /></a></p>
</td>
</tr>
</tbody>
</table>
<p align="center"><span style="font-family: Arial, Helvetica, sans-serif; letter-spacing: normal"> <br /><br /> </span> <span style="color: #1f2251;"><span style="letter-spacing: normal;"> <span style="font-size: xx-small;"><span style="font-size: x-small;">Sicilian Mafia</span></span></span><span style="font-size: xx-small;"><span style="border-collapse: separate; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><span style="font-size: x-small;">&nbsp;</span></span><span style="border-collapse: separate; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><span style="font-size: x-small;">is gebaseerd op rondes. Elke ronde duurt ongeveer 3 maanden na afloop wordt Sicilian-Mafia gereset! Sicilian Mafia spielt immer 3 Monate 1 Ronde. Nach Ablauf wird die Seite resettet! So hat jeder wieder Chancen zu gewinnen! Fette Preise!</span></span></span></span></p>
<p style="text-align: left;">&nbsp;</p>  </div>
</div>
      </div>
      <div id="right_menu">
        <div class="top">&nbsp;</div>
        <div class="items">
          <ul><li class="t">Mitglieder</li><li class="mu"><a><span>1.946</span> Gangsters</a></li>
<li class="mt"><a><span>11</span> heute</a></li>
<li class="mo"><a><span>25</span> Online</a></li>
</ul>
          <ul><li class="t">Linkpartner</li><li><a target="_blank" href="http://www.top100lijsten.be/games/cgi-bin/toplist.pl?action=click_in&amp;account=Peggy">Stem op Sicilian-Mafia 1</a></li>
<li><a target="_blank" href="http://www.gametop200.com/in.php?webid=28">Stem op Sicilian-Mafia 2</a></li>
<li><a target="_blank" href="http://www.dutchleader.nl/top50/in.php?userid=Peggy&amp;siteid=1">Stem op Sicilian-Mafia 3</a></li>
<li><a target="_blank" href="http://www.gamesitestop100.com/in.php?site=18247">Stem op Sicilian-Mafia 4</a></li>
<li><a target="_blank" href="http://www.maffialijst.nl/?in=75">Stem op Sicilian-Mafia 5</a></li>
<li><a target="_blank" href="http://www.gamelist.be/top_lijst.php?in=46">Stem op Sicilian-Mafia 6</a></li>
<li><a target="_blank" href="http://toplist.criminal-intent.nl/">Stem op Sicilian-Mafia 7</a></li>
<li><a target="_blank" href="http://tplist.comxa.com/vote.php?id=13">Stem op Sicilian-Mafia 8</a></li>
<li><a target="_blank" href="http://www.top100nl.net/cgi-bin/toplijst.cgi?hitin=1273365301">Stem op Sicilian-Mafia 9</a></li>
<li><a target="_blank" href="http://game-toplist.de/vote/Peggy.php">Stem op Sicilian-Mafia 10</a></li>
<li><a target="_blank" href="http://www.topsiteguide.net/topreg.asp?site=MaffiaToplijst&amp;account=241783">Eigen Maffia Toplijst - Stemmen!</a></li>
<li><a target="_blank" href="http://donna-peggy.hyves.nl/">Hyves Sicilian-Mafia.nl</a></li>
<li><a target="_blank" href="http://www.linktoevoegen.nl/stemmen/2349/up">Link toevoegen</a></li>
</ul>
        </div>
        <div class="bottom">&nbsp;</div>
      </div>
    </div>
    <div id="site_footer">
      &copy; <strong>Sicilian-mafia.nl</strong> Alle Rechte vorbehalten | <span style="cursor: pointer" onclick="document.location='http://www.sicilian-mafia.nl/impressum'">Impressum</span><span style="position: absolute; top: 0; left: 0; text-indent: -10px; overflow: hidden; width: 1px; height: 1px"><img src="../img01.bgstatic.de/images/browsergames_vote.gif" width="1" height="1"/></span>
    </div>
    <script type="text/javascript">
      var d = new Date();
      t1 = parseInt((d.getTime()-d.getTimezoneOffset()*60000).toString().substring(0, 10));
      t2 = 1318697356;
      tz = Math.round((t1-t2)/3600);
      var expires = new Date();
      var expdate = expires.getTime();
      expdate += 3600*1000*360;
      expires.setTime(expdate);
      var tt = new Date().getHours();
      var hh = new Date().getMinutes();
      var newCookie='tz='+tz+'; path=/; expires='+expires.toGMTString();
      window.document.cookie=newCookie;
    </script>
    <script type="text/javascript">Cufon.now();</script>
    <script>
      if (document.getElementById('overlay')) {
        document.getElementById('overlay').style.visibility='hidden';
        document.getElementById('overlay').style.top='61px';
      }
    </script>
    <script type="text/javascript">

      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-2268134-19']);
      _gaq.push(['_trackPageview']);

      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();

    </script>
<script>
document.body.style.marginTop = '30px';
</script>
<div id="language_bar" style="position: absolute; top: 0; left: 0; right: 0; height: 20px; background: #333; border-bottom: 1px solid #444; font-size: 11px; font-family: Arial; color: #aaa; font-weight: bold; text-align: center; padding: 5px 0; line-height: 20px">





<?php




$hp = mysql_query("SELECT * FROM user_pokemon WHERE username='".$_SESSION['username']."'")
                    or die("Failed to fetch your hp.");
$hppp  = mysql_fetch_array($hp);

?>







<?php
    if (isset($_POST['Changeactive'])) {
        $_SESSION['current_pokemon'] = $_POST['Changeactive'];
    }
?>


    <table width="686" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="white">
        <p style="text-align:left;margin-left:5px;">to change active pokemon simply click the slot number</p>
<form name="ChangeSubmit" id="ChangeSubmit" method="post" action="">    
<?php
    function bgColor($var) {
        if ($_SESSION['current_pokemon'] == $var) {
            return 'bgcolor="#FF9900"';
        } else {
            return 'bgcolor="#333333"';
        }
    }

    function pokmessage($var) {
        if ($_SESSION['current_pokemon'] == $var) {
            return 'ACTIVE';
        } else {
            return '<a href="Javascript:ChangeActive(\''.$var.'\');">'.$var.'</a>';
        }
    }
?>
<input type="hidden" name="Changeactive" id="Changeactive" value=""/>
</form>
    <tr bordercolor="black">
<?php for ($x=1;$x<7;$x++) { ?>
        <td <?php echo bgColor($x); ?>>
            <center class="style7">
                <span class="style7"><b>
                    <?php 
                        if (isset($pokemon->{"pok" . $x}['pokeNAME'])) {
                            echo pokmessage($x);
                        } else {
                            echo $x;
                        }


                    ?>
                </b></span>
            </center>
        </td>
<?php } ?>      
    </tr>


     <tr bordercolor="black">

<?php 
    for ($x=1;$x<=6;$x++) {
        if (isset($pokemon->{"pok" . $x}['pokeNAME'])) { ?>
       <th scope="row" align="center" width="70px">
            <p><img src="/images/pokemon/<?php echo $pokemon->{"pok" . $x}['pokePIC']; ?>" width="32" height="32">
            <p><?php echo $pokemon->{"pok" . $x}['pokeNAME'].'<br/>';  echo 'Level:'.$pokemon->levels[($x-1)]; ?> </p>
             <span class="style2">Hp:







            </span>      </th>
    <?php } else { ?>
            <th scope="row" align="center" width="70px">
            <p>Empty Slot</p>
            </th>
    <?php }
    }
?>
      </tr>

</table>

    <p>
      <script language="Javascript" type="text/javascript">
    function ChangeActive(VAR) {
        document.getElementById("Changeactive").value = VAR;
        ChangeSubmit.submit()
    }
    </script>
</p>
    <p>&nbsp;    </p>
</div>
  </body>

<!-- Mirrored from www.sicilian-mafia.nl/ by HTTrack Website Copier/3.x [XR&CO'2010], Sat, 15 Oct 2011 14:49:20 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=ISO-8859-15"><!-- /Added by HTTrack -->
</html>





Don't see why its not working .... It works on its own page e.g if the first bit of code is on its own . But not if i add it to php / html pages that has body tags and head tags

Is This A Good Question/Topic? 0
  • +

Replies To: Java script works on its own page but not with another page

#2 rpgmaker  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 224
  • Joined: 02-October 11

Re: Java script works on its own page but not with another page

Posted 16 October 2011 - 07:34 AM

Got it working now the new code is

<?php include('include/session.php'); 


		$sql = "SELECT * FROM user_pokemon WHERE username='$_SESSION[username]'";
$result = mysql_query($sql) or die(mysql_error());
$battle_get = mysql_fetch_array($result);


 
?>




<?php

include "config.php";   

$hp = mysql_query("SELECT * FROM user_pokemon WHERE username='".$_SESSION['username']."'")
					or die("Failed to fetch your hp.");
$hppp  = mysql_fetch_array($hp);

?>







<?php
	if (isset($_POST['Changeactive'])) {
		$_SESSION['current_pokemon'] = $_POST['Changeactive'];
	}
?>
<style type="text/css">
<!--
.style3 {font-size: 9px}
-->
</style>

	<table width="64" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="white">
		<p class="style3" style="text-align:left;margin-left:5px;">to change active pokemon simply click the slot number</p>
<form action="" method="post" name="ChangeSubmit" class="style3" id="ChangeSubmit">	
<?php
	function bgColor($var) {
		if ($_SESSION['current_pokemon'] == $var) {
			return 'bgcolor="#FF9900"';
		} else {
			return 'bgcolor="#333333"';
		}
	}
			
	function pokmessage($var) {
		if ($_SESSION['current_pokemon'] == $var) {
			return 'ACTIVE';
		} else {
			return '<a href="Javascript:ChangeActive(\''.$var.'\');">'.$var.'</a>';
		}
	}
?>
<input type="hidden" name="Changeactive" id="Changeactive" value=""/>
</form>
	<tr bordercolor="black">
<?php for ($x=1;$x<7;$x++) { ?>
		<td class="style3" <?php echo bgColor($x); ?>>
			<center class="style7">
				<span class="style7"><b>
					<?php 
						if (isset($pokemon->{"pok" . $x}['pokeNAME'])) {
							echo pokmessage($x);
						} else {
							echo $x;
						}
					
			
					?>
				</b></span>
			</center>		</td>
<?php } ?>		
	</tr>
			   
			   
     <tr bordercolor="black">

<?php 
	for ($x=1;$x<=6;$x++) {
		if (isset($pokemon->{"pok" . $x}['pokeNAME'])) { ?>
	   <th width="78" align="center" class="style3" scope="row">
			<p><img src="/images/pokemon/<?php echo $pokemon->{"pok" . $x}['pokePIC']; ?>" width="32" height="32">
			<p><?php echo $pokemon->{"pok" . $x}['pokeNAME'].'<br/>';  echo 'Level:'.$pokemon->levels[($x-1)]; ?> </p>
		 Hp:
		 <?php	include_once "hp".$x.".php"; ?>    		 </th>
	<?php } else { ?>
			<th width="286" align="center" class="style3" scope="row">
			<p>Empty Slot</p>			</th>
	<?php }
	}
?>
                 </tr>
               </table>
			   
    <span class="style3">
<script language="Javascript" type="text/javascript">
	function ChangeActive(VAR) {
		document.getElementById("Changeactive").value = VAR;
		ChangeSubmit = document.getElementById("ChangeSubmit");
		ChangeSubmit.submit()
	}
</script>





Of course ill have to make it safe from sql injection but it works :whistling:
Was This Post Helpful? 0
  • +
  • -

#3 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3099
  • View blog
  • Posts: 10,885
  • Joined: 08-August 08

Re: Java script works on its own page but not with another page

Posted 16 October 2011 - 08:02 AM

Good that it's working. Here are some questions to think about:
  • Why do you have lines 7 -16 and 22-31?
  • Why are you sticking CSS inline with your HTML?
  • Why are you sticking Javascript inline with your HTML?
  • Why are you using tables to do a job for CSS?
  • Is mixing PHP, HTML, CSS, and Javascript making your code readable?

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1