0

Hi,

Everything is working fine except the start time. Once I click start, i want to see start time is ticking but start time does not change. I want future time static and start time dynamic.

Please advise.

<html>

<?PHP
$From = date("H:i:s");
echo "From  $From ";
$Minutes = 1;
echo "<br />";
$To = date("H:i:s", strtotime($From)+($Minutes*60));
?>

<SCRIPT language="JavaScript">

function newtext()
{
document.getElementById("stBtn").disabled = true;
starttime = '<?php echo $From ;?>';
futuretime = '<?php echo $To ;?>';

document.getElementById("start").innerHTML = starttime;
document.getElementById("future").innerHTML = futuretime;
setTimeout("moretext()",1 * 60000);
 }

function moretext()
{

document.getElementById("subBtn").disabled = true;
}

</SCRIPT>

</HEAD>

<BODY>

<FORM name="myform" method="post" action="sessionS1.php">

<table width='600' cellpadding='5' cellspacing='5' border='1'> 
<tr> <td> <p id="start"></p> </td> <td> <p id="future"></p>  </td> <td> </td> </tr>

<tr><td colspan=6 align='right'><INPUT class = "button" id="stBtn" TYPE="button" name= mytext value="StartExam" onClick="newtext

()"></td></tr> 

<tr><td colspan=6 align='right'><input type='submit' id="subBtn"value='Score' name='btn_score'></td></tr> 

</table> 

</FORM>

</body>
</html>

Edited by bangla

2
Contributors
5
Replies
6
Views
4 Years
Discussion Span
Last Post by diafol
0

From what I can see, moretext() isn't doing anything. You call it, but it just ensures that the button is still disabled. Move your scripts to the end of the page (just above </body>).

If you place document.write('hi'); or similar to the moretext() function, you'll see if it's actually being called. Alternatively, use alert() or console.log

Can you use setInterval / clearInterval for this?

Also the start time isn't strictly true as it depends on the button click, which could be a while after the time displayed. Why not just have a countup or countdown in seconds?

Just a question - will refreshing the page give the applicant another minute?

Edited by diafol

0

refresh gives me current time every 2 seconds but it refreshes the entire page. then i have to click start again.

moretext() is disabling score button after 1 minute. it is working fine. newtext() calls moretext().

I am not sure what you are trying to say. All I want the starttime to tick without refreshing the entire page.

Please help.

0

I was just saying that you haven't got any routine for changing time. Here's some stuff wwhich may help. I'm no js guru, but here's an attempt at a count-up. You can get much better examples from searching Google.

<html>
<head>
</head>
<BODY>
<FORM name="myform" method="post" action="sessionS1.php">
<table width='600' cellpadding='5' cellspacing='5' border='1'> 
<tr> <td> <p id="start">0</p> </td> <td> <p id="future"></p>  </td> <td> </td> </tr>
<tr><td colspan=6 align='right'><INPUT class = "button" id="stBtn" TYPE="button" name= mytext value="StartExam" onClick="newtext
()"></td></tr> 
<tr><td colspan=6 align='right'><input type='submit' id="subBtn"value='Score' name='btn_score'></td></tr> 
</table> 
</FORM>
<SCRIPT language="JavaScript">

var starttime = 0;
var futuretime = 20;

document.getElementById("future").innerHTML = futuretime;

function newtext()
{
    document.getElementById("stBtn").disabled = true;

    var goClock=self.setInterval(function(){
        if(starttime >= futuretime){
            self.clearInterval;
            document.getElementById("stBtn").disabled = false;
        }else{
            changeClock();
        }
    },1000);
}
function changeClock()
{
    starttime++;
    document.getElementById("start").innerHTML = starttime;
}
</SCRIPT>
0

Thanks much. Thats a lot better.

But I would be pleased if you could help me for the below:

  1. How can i change 0 to currenttime
  2. Then add 5 minutes to currenttime = futuretime
  3. then it will run from current time till 5 minutes after.
  4. it displays current time and futuretime

    <SCRIPT language="JavaScript">
    
    var thetime=new Date();
    var nhours=thetime.getHours();
    var nmins=thetime.getMinutes();
    var nsecn=thetime.getSeconds();
    
    
    var starttime = nmins;
    var maxm = nmins + 5*60 ;
    var futuretime = maxm;
    document.getElementById("future").innerHTML = futuretime;
    function newtext()
    {
        document.getElementById("stBtn").disabled = true;
        var goClock=self.setInterval(function(){
            if(starttime >= futuretime){
                self.clearInterval;
                document.getElementById("stBtn").disabled = false;
            }else{
                changeClock();
            }
        },1000);
    }
    function changeClock()
    {
        starttime++;
        document.getElementById("start").innerHTML = starttime;
    }
    </SCRIPT>
    

Edited by bangla

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.