?
Solved

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

Posted on 2004-08-26
4
Medium Priority
?
191 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
[X]
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
  • 3
4 Comments
 
LVL 2

Accepted Solution

by:
sarahk earned 2000 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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.
Suggested Courses

764 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