hi
i used a javascript countdown timer as:

<form name="counter"><input type="text" size="8" 
name="d2"></form> 
<script> 
<!-- 
// 
 var min=5 
 var seconds=0 
 document.counter.d2.value='5' 
function display(){ 
 if (seconds<=0){ 
    min-=1 
    seconds=60
 } 
 if (min<=-1){ 
    seconds=0 
    min+=1 
 } 
 else 
    seconds-=1 
    document.counter.d2.value=min+":"+seconds 
    setTimeout("display()",1000) 
} 
display()

--> 
</script>

for clock ticking purpose.
and

<SCRIPT LANGUAGE="JavaScript"><!--
setTimeout('document.tform.submit()',300000);
//--></SCRIPT>

for auto submit purpose.

but the problem is when we are refresh the page the clock start again from the beginning . how i resolve the problem ??
plz help me.

I dont really understand why you want to avoid timer restart after a page reload.

If you want to carry Javascript variable values across page changes or reloads, You can use cookies.
If you dnt knw how to use cookies with JavaScript.
W3Schools got a little tutorial for cookies..
see this link:
http://w3schools.com/js/js_cookies.asp
Hope that helped :-)
Have a nice day...

Regards,
Rineez Ahmed N
Livares InfoTech
<FAKE SIGNATURE>

What you're saying is that the counter should continue regardless of to where you navigate (e.g. you've been on this site a total of x minutes, y seconds)?
You can't carry over js scripts from one page to the next unless you use something like Ajax (I may be wrong).

Probably your best bet would be to place a value into a cookie (js or php) or $_SESSION variable (php) or even a database (php) when the user logs in or arrives (e.g. track the IP address).

If you want a 'ticker', get js to read a cookie or get it to read a session variable or DB value, via php, on page load and then calculate time elapsed (I suggest using php or a MySQL date function for this, although js has some time calculating functions) from then - that's then your starting point.

Once you've done that, set up your js iterator to add a time increment to this value and display to the screen.

What you're saying is that the counter should continue regardless of to where you navigate (e.g. you've been on this site a total of x minutes, y seconds)?

:-/ hey.. wat he need is a countdown timer ardav.
I think it is clear from the javascript code, and it is there in the thread title too.

Any ways there is no need of Ajax here.. I suggest it is always nice to keep Ajax out unless you cant live without it.

If you want a 'ticker', get js to read a cookie or get it to read a session variable or DB value, via php, on page load and then calculate time elapsed (I suggest using php or a MySQL date function for this

Yes ofcourse any of these techniques can do the job..
But if all you need is a simple countdown timer then I wouldn't suggest messing up your php code or database design for that. Because it will be just an unnecessary overhead for your server side.

Keep it cool and let the javascript do the job, if its just a simple Countdown before Form Submit.:)


Store the timer values in cookies using javascript.
Update the cookie values along with your count down variables.(writing a seperate function to get and set cookie is a cool idea)
Always initialise your timer from the value you get from cookie.
You might want to reset the cookies when the countdown ends.

all the best

Rineez Ahmed N
Livares InfoTech
<FAKE SIGNATURE>
---------------------------------------------------------------------------------
I do not have any wisdom to share with you
I do not have any knowledge to share with you..
All I own are thoughts to share with you

Sorry fella, missed the 'countdown' and the '-', was doing a few things at the same time (no excuse!). However, if cookies disabled, you may still want to use an SS solution if you need to carry on the countdown between page loads. Granted, my suggestions would put a load on the server.

So yeah, I humbly beg your pardon and deserve a few dry backhand slaps for not reading your post correctly. Thanks for letting me see the error of my ways Rin - do I feel stupid now.

;-) lol.. its alright.. its nice that u find time for responding to forums in between busy work.
and Yeh you got a point there...
If you wish to address visitors who have disabled cookies in their browser, Session will be unavoidable...
this link has some examples for using php session if you need
http://in3.php.net/manual/en/ref.session.php


Regards,
Rineez Ahmed N

;-) lol.. its alright.. its nice that u find time for responding to forums in between busy work.
and Yeh you got a point there...
If you wish to address visitors who have disabled cookies in their browser, Session will be unavoidable...
this link has some examples for using php session if you need
http://in3.php.net/manual/en/ref.session.php


Regards,
Rineez Ahmed N

My turn to embarris people :P, PHP Sessions still use cookies so if cookies aren't enabled then sessions will not work.

Can't remember where I read it but supposivly so.

In wich case you would need to save the current mins seconds etc into a MySql database and retreive it each time.

BUT I think more people have JavaScript disabled than cookies so is it really an issue?

Sessions don't have to be propogated by cookie, you can use db, $_GET, $_POST. Indeed, the more secure examples use a db to store session values.

Seeing as you've turned this into a point-scoring exercise Josh, I believe that Rin is still miles ahead. Pah! Pesky kids ... grumble ... mutter ... doh!

woops.. i dint mean to embaress nyone josh...
well any ways session also needs cookie support!.. is a surprising new info for me..:-O I thought it stores info on Server side only

I tested it just now and truns out its true.. not just for PHP but for JSP too and probably any scripting languages.

Now I see why my Web Browser settings has an option saying "Accept session cookies only" :icon_biggrin:

People rarely disable that. Its only third party cookies most users fear.

However I think the info stored is just some id number to recognize the user browser. :idea: !!

By the way.. how do people score points in here?? guss i have to read the get start Guide

woops.. i dint mean to embaress nyone josh...

Don't worry Rin, you didn't embarrass me, I embarrassed myself!:$

Don't worry Rin, you didn't embarrass me, I embarrassed myself!:$

Lol ;)

Now wat should I do to get any moderators to just remove my non standard Signatures instead of marking them FAKE

And Hey.. Dont call me Rin .. call me Rineez. i think that is short enough..

hi i just want to ask and ask your help . can you guys help to make timer in my quiz page. seriously i have no idea how to do it. plus im still new in this field around 7 month , so i dont know where to put the code and what i need to write in the code . kindly hope your help.sorry for my broken english
this is my code

<style>

html
{
 font-family:tahoma;
}

</style>

<?php
    function gettitle($id)
    {



    $q="SELECT title FROM elearning_title WHERE title_id='$id'";
    list($name)=mysql_fetch_row(mysql_query($q));


    return $name;

    }

?>

<?php if(isset($_POST['submit']))
{

        $title_id = $_GET['cid'];       
        $upload_by =  $_SESSION["log"]["userid"];


        $group1 = $_POST['group']['1'];
        $group2 = $_POST['group']['2'];
        $group3 = $_POST['group']['3'];
        $group4 = $_POST['group']['4'];


        $insert=mysql_query("insert into elearning_history set user_id='$upload_by',title_id='$title_id '");






        //$insert=mysql_query("update elearning_history set score='$score' where title_id='$title_id' and user_id='$upload_by' ");
//$insert=mysql_query("insert into elearning_history set user_id='$upload_by',title_id='$title_id ', ans_1='$group1', ans_2='$group2',ans_3='$group3',ans_4='$group4',ans_5='$group5', score='$score'");

        $a=1; 

        while ($a <= count($_POST['group']))
        {   


            $ans="ans_".$a;
            $studentans =  $_POST['group'][$a];

            $query=mysql_query("update elearning_history set $ans='$studentans' where title_id='$title_id' and user_id='$upload_by' ");

        $a++;
        }



        $query="SELECT * FROM elearning_question WHERE title_id='$title_id'";
        $q=mysql_query($query); 

        $score=0;
        $i=1;
        while($row=mysql_fetch_array($q))   
        {

            if( $row['correct_answer'] == $_POST['group'][$i])
            {   
                $score++;

            }

            $i++;

        }

        $final=mysql_query("update elearning_history set score='$score' where title_id='$title_id' and user_id='$upload_by'");

         //$q=mysql_query("SELECT COUNT(*) FROM elearning_question WHERE title_id = '$title_id'");
                    //list($int)=mysql_fetch_row($q); 
                    //echo $int;
?>                  
                <script type="text/Javascript">
            <!--
                alert("Quiz Successful!");

    -->
            </script>

            <body onLoad="self.setTimeout('parent.parent.location.reload().GB_hide()', 60);">

<?php    
}

?>
<?php
    $title_id = $_GET['cid'];
?>

<h2><center><?php echo gettitle($title_id ); ?></center></h2>
 <form method="post">
<table border ="0" width="80%" style="background-color:#FFFFFF; border-collapse:collapse; table-layout:fixed" align="center"  cellpadding="8" cellspacing="3">
    <tr bgcolor="#99CCFF">
        <th width="5%" height="35">Bil</th>
        <th width="95%">Question</th>
    </tr>

<?php

    $title_id = $_GET['cid'];

    $query="SELECT * FROM elearning_question WHERE title_id='$title_id'";
    $q=mysql_query($query); 

    $count=1;
    $i=1;
    while($row=mysql_fetch_array($q))
    {


        if ( $row['question_type'] == '1')
        {
    ?> 

        <tr>
            <td align="center"><input name="id"  type="hidden" value="bil"> <?php echo $count; ?></td>

            <td><?php echo $row['question']; ?></td>
        </tr>    

        <tr>
            <td></td>
            <td width="15%"><input type="radio" name="group[<?php echo $i; ?>]" value="1" required>A.<?php echo $row['answer_one']; ?></td>      
        </tr>

        <tr>
            <td></td>
            <td><input type="radio" name="group[<?php echo $i; ?>]" value="2" required>B.<?php echo $row['answer_two']; ?></td>

        </tr>

        <?php 
        $i++;
        }


        else if ($row['question_type'] == '2')
        {
         ?>


        <tr>
            <td align="center"><input name="id"  type="hidden" value="bil"> <?php echo $count; ?></td>

            <td><?php echo $row['question']; ?></td>
        </tr>    
        <tr>
            <td></td>
            <td width="15%"><input type="radio" name="group[<?php echo $i; ?>]" value="1" required>A.<?php echo $row['answer_one']; ?></td>

        </tr>

        <tr>
            <td></td>
            <td width="15%"><input type="radio" name="group[<?php echo $i; ?>]" value="2" required>B.<?php echo $row['answer_two']; ?></td>
        </tr>

        <tr>
            <td></td>
            <td width="15%"><input type="radio" name="group[<?php echo $i; ?>]" value="3" required>C.<?php echo $row['answer_three']; ?></td>
        </tr>

        <tr>
            <td></td>
            <td width="15%"><input type="radio" name="group[<?php echo $i; ?>]" value="4" required>D.<?php echo $row['answer_four']; ?></td>
        </tr>


    <?php
        $i++;
        }
    $count++;}
    ?>
    <tr>
        <td></td>
        <td align="center"><input type="submit" name="submit" value="Done" id="submit"></td>
    </tr>
  </table>
  </form>
  <br />





<style>

html


    {


 font-family:tahoma;
}

</style>





<?php
    function gettitle($id)
    {
    $q="SELECT title FROM elearning_title WHERE title_id='$id'";
    list($name)=mysql_fetch_row(mysql_query($q));




return $name;

}



?>

<?php if(isset($_POST['submit']))
{



    $title_id = $_GET['cid'];       
    $upload_by =  $_SESSION["log"]["userid"];


    $group1 = $_POST['group']['1'];
    $group2 = $_POST['group']['2'];
    $group3 = $_POST['group']['3'];
    $group4 = $_POST['group']['4'];


    $insert=mysql_query("insert into elearning_history set user_id='$upload_by',title_id='$title_id '");






    //$insert=mysql_query("update elearning_history set score='$score' where title_id='$title_id' and user_id='$upload_by' ");


//$insert=mysql_query("insert into elearning_history set user_id='$upload_by',title_id='$title_id ', ans_1='$group1', ans_2='$group2',ans_3='$group3',ans_4='$group4',ans_5='$group5', score='$score'");



    $a=1; 

    while ($a <= count($_POST['group']))
    {   


        $ans="ans_".$a;
        $studentans =  $_POST['group'][$a];

        $query=mysql_query("update elearning_history set $ans='$studentans' where title_id='$title_id' and user_id='$upload_by' ");

    $a++;
    }



    $query="SELECT * FROM elearning_question WHERE title_id='$title_id'";
    $q=mysql_query($query); 

    $score=0;
    $i=1;
    while($row=mysql_fetch_array($q))   
    {

        if( $row['correct_answer'] == $_POST['group'][$i])
        {   
            $score++;

        }

        $i++;

    }

    $final=mysql_query("update elearning_history set score='$score' where title_id='$title_id' and user_id='$upload_by'");

     //$q=mysql_query("SELECT COUNT(*) FROM elearning_question WHERE title_id = '$title_id'");
                //list($int)=mysql_fetch_row($q); 
                //echo $int;


?>                  
                <script type="text/Javascript">
            <!--
                alert("Quiz Successful!");

    -->


        </script>

        <body onLoad="self.setTimeout('parent.parent.location.reload().GB_hide()', 60);">



<?php    
}

?>
<?php
    $title_id = $_GET['cid'];
?>





<h2><center><?php echo gettitle($title_id ); ?></center></h2>
 <form method="post">
<table border ="0" width="80%" style="background-color:#FFFFFF; border-collapse:collapse; table-layout:fixed" align="center"  cellpadding="8" cellspacing="3">
    <tr bgcolor="#99CCFF">
        <th width="5%" height="35">Bil</th>
        <th width="95%">Question</th>
    </tr>





<?php



$title_id = $_GET['cid'];

$query="SELECT * FROM elearning_question WHERE title_id='$title_id'";
$q=mysql_query($query); 

$count=1;
$i=1;
while($row=mysql_fetch_array($q))
{


    if ( $row['question_type'] == '1')
    {
?> 

    <tr>
        <td align="center"><input name="id"  type="hidden" value="bil"> <?php echo $count; ?></td>

        <td><?php echo $row['question']; ?></td>
    </tr>    

    <tr>
        <td></td>
        <td width="15%"><input type="radio" name="group[<?php echo $i; ?>]" value="1" required>A.<?php echo $row['answer_one']; ?></td>      
    </tr>

    <tr>
        <td></td>
        <td><input type="radio" name="group[<?php echo $i; ?>]" value="2" required>B.<?php echo $row['answer_two']; ?></td>

    </tr>

    <?php 
    $i++;
    }


    else if ($row['question_type'] == '2')
    {
     ?>


    <tr>
        <td align="center"><input name="id"  type="hidden" value="bil"> <?php echo $count; ?></td>

        <td><?php echo $row['question']; ?></td>
    </tr>    
    <tr>
        <td></td>
        <td width="15%"><input type="radio" name="group[<?php echo $i; ?>]" value="1" required>A.<?php echo $row['answer_one']; ?></td>

    </tr>

    <tr>
        <td></td>
        <td width="15%"><input type="radio" name="group[<?php echo $i; ?>]" value="2" required>B.<?php echo $row['answer_two']; ?></td>
    </tr>

    <tr>
        <td></td>
        <td width="15%"><input type="radio" name="group[<?php echo $i; ?>]" value="3" required>C.<?php echo $row['answer_three']; ?></td>
    </tr>

    <tr>
        <td></td>
        <td width="15%"><input type="radio" name="group[<?php echo $i; ?>]" value="4" required>D.<?php echo $row['answer_four']; ?></td>
    </tr>


<?php
    $i++;
    }
$count++;}
?>
<tr>
    <td></td>
    <td align="center"><input type="submit" name="submit" value="Done" id="submit"></td>
</tr>


 </table>
  </form>
  <br />

Start a new thread. This is just tagging on to a 6 year old thread that I suspect nobody wants to read or resurrect. Thanks.

This article has been dead for over six months. Start a new discussion instead.