[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

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

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
Kyle Abrahams
Asked:
Kyle Abrahams
  • 3
1 Solution
 
sarahkCommented:
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
 
Kyle AbrahamsSenior .Net DeveloperAuthor Commented:
YOU ROCK!
0
 
Kyle AbrahamsSenior .Net DeveloperAuthor Commented:
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
 
Kyle AbrahamsSenior .Net DeveloperAuthor Commented:
never mind, got it:

First line of GetStarted should be:

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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now