Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

java typing driving me crazy

Status
Not open for further replies.

Cendent

Programmer
Joined
May 25, 2006
Messages
3
Location
US
Hi, I've been trying to figuer this out for weeks now. I'm hoping someone here can help, or point me in the right directions. The code bellow is suppose to type out text1 2 and 3 at the same time, text 1 & 2 work fine but 3 seems to stop everything. But if I put "Hello" into the effects_text on the PHP side then it works fine or if there is nothing in text3 it works fine aswell. I'm positive it's not coming from the PHP side cause I'm able to print out the variables text1, text2, and text3 in javascript. Here is the code:
Code:
<?php
session_start();
require_once('../../includes/database.php');
DBConnection();

$qr = mysql_query("select round, cha_string, opp_string, effect_string from `combat` where ID = '". $_SESSION['ID'] ."'");
$row = mysql_fetch_array($qr);
$round = $row['round'];

if ($round == "0") {
	echo "Starting...";
} else {
	echo "<CENTER><B> ROUND $round </B></CENTER><BR>";
	$cha_text = $row['cha_string'];
	$opp_text = $row['opp_string'];
	$effects_text = $row['effect_string'];
}

?>
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
<!--
var text= <?php print "'".$cha_text."'"; ?>;   
var delay=100;
var currentChar=1;
var destination="[not defined]";

var text2= <?php print "'".$effects_text."'"; ?>;
var delay2=100;
var currentChar2=1;
var destination2="[not defined]";


var text3= <?php print "'".$effects_text."'"; ?>;   
var delay3=100;
var currentChar3=1;
var destination3="[not defined]";

function type()
{
  if (document.getElementById)
  {
    var dest=document.getElementById(destination);
    if (dest)
    {
      dest.innerHTML=text.substr(0, currentChar);
      currentChar++
      if (currentChar>text.length)
      {
        currentChar=1;
        setTimeout("type()", 10000000000);      	
	  }
      else
      {
        setTimeout("type()", delay);
      }
    }
  }
}

function type2()
{
  if (document.getElementById)
  {
    var dest=document.getElementById(destination2);
    if (dest)
    {
      dest.innerHTML=text2.substr(0, currentChar2);
      currentChar2++
      if (currentChar2>text2.length)
      {
        currentChar2=1;
        setTimeout("type2()", 100000000000); 
		
		//setTimeout("startTyping3(text3, '100', \"textDestination3\")", 5000);      	
	  }
      else
      {
        setTimeout("type2()", delay2);
      }
    }
  }
}


function type3()
{
  if (document.getElementById)
  {
    var dest=document.getElementById(destination3);
    if (dest)
    {
      dest.innerHTML=text3.substr(0, currentChar3);
      currentChar3++
      if (currentChar3>text3.length)
      {
        currentChar3=1;
        setTimeout("type3()", 100000000000);       	
	  	parent.controls.location.href = "controls.php";
	  	parent.challanger.location.reload(); 
    	parent.opponet.location.reload();
	  // Refresh the pages here...
	  }
      else
      {
        setTimeout("type3()", delay3);
      }
    }
  }
}




function startTyping(textParam, delayParam, destinationParam)
{
  text=textParam;
  delay=delayParam;
  currentChar=1;
  destination=destinationParam;
  type();
}

function startTyping2(textParam2, delayParam2, destinationParam2)
{
  text2=textParam2;
  delay2=delayParam2;
  currentChar2=1;
  destination2=destinationParam2;
  type2();
}

function startTyping3(textParam3, delayParam3, destinationParam3)
{
  text3=textParam3;
  delay3=delayParam3;
  currentChar3=1;
  destination3=destinationParam3;
  type3();
}
function myScroll() { // scroll to bottom of wwindow
    window.scrollBy(0,100)
    setTimeout('myScroll()',1000); // scrolls every 1000 miliseconds
}
//-->
</SCRIPT>
<title></title>
</head>
<body>

<DIV ID="textDestination">...</DIV>
<BR><BR>
<DIV ID="textDestination2">...</DIV>
<BR>
<DIV ID="textDestination3">...</DIV>
</body>
<SCRIPT LANGUAGE="JavaScript">
<!--
startTyping(text, 100, "textDestination");
startTyping2(text2, 100, "textDestination2");
startTyping3(text3, 100, "textDestination3");   
myScroll();
//-->
</SCRIPT>
</html>


Any ideas?
Thanks in advance,
Josh
 
Sorry I was experimenting and forgot to change something back:
var text2= <?php print "'".$effects_text."'"; ?>;
should be
var text2= <?php print "'".$opp_text."'"; ?>;
Still having same problem
 
Since we have no idea what values your PHP are getting from the database, please show your HTML output, not the PHP script.

Lee
 
For testing purposes I've put these into the database.
HTML out put:

TESTING TEXT 1


TESTING TEXT 2

TESTING TEXT 3
 
That's not quite what I was referring to. When the PHP page is processed and you see the page in the browser, click on View, then Source, and show the relevant HTML code here.

Lee
 
Text 1 and 2 work, while text 3 does not. And guess what? The text3 function is different from the other two!

Try making it the same and see if that fixes the issue.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top