Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2004-08-26
4
186 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
ID: 11909576
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 40

Author Comment

by:Kyle Abrahams
ID: 11920082
YOU ROCK!
0
 
LVL 40

Author Comment

by:Kyle Abrahams
ID: 11920353
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 40

Author Comment

by:Kyle Abrahams
ID: 11920373
never mind, got it:

First line of GetStarted should be:

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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 …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
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 look for a specific file type in a local or remote server directory using PHP.

840 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