Solved

PHP, HTML, & Javascript . . . need help debugging.  URGENT

Posted on 2004-08-26
4
184 Views
Last Modified: 2006-11-17
Code:

----------------------------------------------------------------------------------------------------------------------------------------------------------------
someurl.htm

<html>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<head>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      <title>Sayhi2me Advertisement</title>
</head>

        <frameset rows="25%,75%">
               <frame src= "index.htm" name ="sidemenu" noresize scrolling ="yes">
               <frame src= "http://www.google.com" name = "mainwindow">
        </frameset>

<body>


</html>

----------------------------------------------------------------------------------------------------------------------------------------------------------------
index.htm


<html>

<?php
   $conn = mysql_connect("localhost", "user", "****");
   

   mysql_select_db("trivia", $conn);
   
   

   $id = 1;
   $sql = "SELECT Question,Answer1,Answer2,Answer3,Answer4,Answer5,UserLink,Correct FROM `trivia questions` where ID=$id";  


   $result     = mysql_query($sql, $conn);

   $q = mysql_result($result, 0, "Question");

   $a1 = mysql_result($result, 0, 'Answer1');
   $a2 = mysql_result($result, 0, 'Answer2');
   $a3 = mysql_result($result, 0, 'Answer3');
   $a4 = mysql_result($result, 0, 'Answer4');
   $a5 = mysql_result($result, 0, 'Answer5');
   $answer = mysql_result($result, 0, 'Correct');
   $link = mysql_result($result, 0, 'UserLink');

?>


<form name="myForm">
<body onload="getStarted()">
<h3>You must browse this page for:
   <input name="numberShown" type="text" size="2" align="right" onfocus="this.blur()">
 more seconds. <span style="visibility:hidden" id="word"><font color="FF0000">Secret Word: <?PHP $id ?> </font></span></h3>
</body>
</form>



<SCRIPT LANGUAGE="JAVASCRIPT">
parent.main.location.href=" <?PHP print($link) ?>";


function getStarted() {
  //-- Loads the number 10 into the form field.
  parent.myForm.numberShown.value="5"
  //-- Pauses one-second, then calls the subtractOne function.
  myTimer=setTimeout("subtractOne()",1000)
}
function subtractOne() {
  //Subtract 1 from current value in form field.
  var newValue = parseInt(document.myForm.numberShown.value)-1
  //Replace the contents of form field with smaller number.
  document.myForm.numberShown.value = newValue

  //-- If countdown hasn't reached zero, pause then do it again.
  if (newValue > 0) {
    //-- From here on out, this function calls itself once every second.
    myTimer=setTimeout("subtractOne()",1000)
  //-- When countdown does reach zero, stop the timer and call reachedZero().
  }else{
    clearTimeout("myTimer")
    reachedZero()
  }
}

function reachedZero() {
    alert($id);
}

</html>
----------------------------------------------------------------------------------------------------------------------------------------------------------------


Here's what I'm trying to do:


Current:
someurl splits browser into 2 frames.  Loads google in 1, my scripts in another.

Needed:
load link where google is, get scripts working, then reload the frame where the scripts were executed to another php page (I want to create it in this file though.)

What the scripts do:
It's a countdown.  

So go visit $link, meanwhile other side counts down, when countdown reaches zero, want to generate a question (I already have the code for this, just need to know how to move into and out of java script.)  PLEASE HELP!



0
Comment
Question by:Kyle Abrahams
  • 3
4 Comments
 
LVL 2

Accepted Solution

by:
sarahk earned 500 total points
Comment Utility
Here's my take on what you are trying to do.
I have a working copy of it at http://sarahk.pcpropertymanager.com/muck/ee/

I've renamed the files to index.html and bit.php
===============================
index.html
===============================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- doctype is always on line 1-->
<html>
<head>
     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
     <title>Sayhi2me Advertisement</title>
</head>
       <frameset rows="25%,75%">
              <frame src= "bit.php" name ="sidemenu" noresize scrolling ="yes">
              <frame src= "http://www.google.com" name = "mainwindow">
       </frameset>
<body>
</html>

===============================
bit.php
===============================
<html>
<?php
 if (isset($_GET['ready']))
{
      echo "trivia question goes here";
}
else
{
      $link = "/muck/ee/bit.php?ready=1";
      $id = 'squirrell';
?>
<head>
<SCRIPT LANGUAGE="JAVASCRIPT">
function getStarted()
{
  //-- Loads the number 10 into the form field.
  // you were referencing the form incorrectly
  document.myForm.numberShown.value = 10;
  //-- Pauses one-second, then calls the subtractOne function.
  myTimer=setTimeout("subtractOne()",1000)
}

function subtractOne() {
  //Subtract 1 from current value in form field.
  //var newValue = parseInt(document.myForm.numberShown.value)-1;
  var newValue = document.myForm.numberShown.value - 1;
  //Replace the contents of form field with smaller number.
  document.myForm.numberShown.value = newValue;

  //-- If countdown hasn't reached zero, pause then do it again.
  if (newValue > 0)
{
    //-- From here on out, this function calls itself once every second.
    myTimer=setTimeout("subtractOne()",1000)
  //-- When countdown does reach zero, stop the timer and call reachedZero().
  }
else
{
    clearTimeout("myTimer");
    reachedZero();
  }
}

function reachedZero() {
    alert("<?php echo $id; ?>");
      document.location.href=" <?php echo($link) ?>";
}
</script><!-- one issue related to the fact that you didn't close the script section -->
</head>
<body onload="getStarted();">
<form name="myForm">
<h3>You must browse this page for:
   <input name="numberShown" type="text" size="2" align="right" onfocus="this.blur()">
 more seconds. <span style="visibility:hidden" id="word"><font color="FF0000">Secret Word: <?PHP $id ?> </font></span></h3>
</body>
</form>

</body>
<?php
}
?>
</html>
===============================

I hope this is what you were after!

Sarah
0
 
LVL 39

Author Comment

by:Kyle Abrahams
Comment Utility
YOU ROCK!
0
 
LVL 39

Author Comment

by:Kyle Abrahams
Comment Utility
quick question:

instead of www.google.com in index.html we have $link for the user link.

link has to be the same link as link in bit.php.  

is there a simple way to redirect mainwindow?

0
 
LVL 39

Author Comment

by:Kyle Abrahams
Comment Utility
never mind, got it:

First line of GetStarted should be:

  parent.frames['mainwindow'].location.href = "<?php print($link) ?>";
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now