Jump to content
piano0011

buttons not aligning at the center

Recommended Posts

Ok.. i will take a look and also, will the above work and is it good practice to use a separate page for the javascript code? As in <script src="">?

Share this post


Link to post
Share on other sites
4 minutes ago, piano0011 said:

will the above work

I have no idea. We only see small snippets of your code - you are the only one who can see the big picture.

 

5 minutes ago, piano0011 said:

it good practice to use a separate page for the javascript code?

My approch is the same as with php functions. If they are required in more than one script, put them in an included file. Same goes for js. If general purpose js functions for use in several places, use an external file. If only used in the current file then I just put them in <script type="text/javascript"> .. </script> tags in the head section of the page.

Share this post


Link to post
Share on other sites

I can get my php form to process the timer result and insert the record into the database but when I add the header function, it keeps taking me to the header function instead of showing the timer. My guess is that because it is processing the php first, it is doing this. I just like to know if I can have a header function it this is the case?

 

<?php

include_once 'includes/dbh.php';
    $timer = 60;
    $time = $_POST['time'];   
    $user_uid = 'piano0011'; 

      
    
    $sql = "UPDATE primerlevel_tests
            SET time_achieved = ?
            WHERE user_uid = ?
           ";

    $stmt = mysqli_stmt_init($conn);
        if (!mysqli_stmt_prepare($stmt, $sql)) {
          echo 'SQL error';
        } else {
          mysqli_stmt_bind_param($stmt, "ss", $time, $user_uid);
          mysqli_stmt_execute($stmt);
        }

        header("Location: update.php?countdown=success");
        exit();

        


?>
<style type="text/css">
    div.timer {
        text-align: center;
        margin: 15% auto;
    }
    #msg {
        color: red;
    }
</style>
<html>
<head>
<script type="text/javascript">
    var timer = <?php echo $timer ?>;    // 1 minute timer.... 
    var min = 0;
    var sec = 0;
    var active = 1;
    
    function startTimer() {
        if (active==0) return;
        
        if (timer == 0) timer = <?=$timer?> ;
        timer--;
        
        min = parseInt(timer/60);
        sec = parseInt(timer%60);
        
        
        if(timer < 1) {
            $timer = 0;
            min = 0;
            sec = 0;
            document.getElementById("msg").innerHTML = "You have to start again" ;
            document.getElementById("time").value = "00:00:00";
            active = 1;
            return;
        }
        else {
            if (min < 10) min = '0'+min;
            if (sec < 10) sec = '0'+sec;
            document.getElementById("msg").innerHTML = "" ;
            document.getElementById("time").value = "00:" + min.toString() + ":" + sec.toString();
        }

        setTimeout(function() {
        startTimer();
        }, 1000);
    }

    function stop() {
        if (min + sec > 0) {
            alert("Thank you for completing the test. You finished the test at: " +  min.toString() + ":" + sec.toString());
            document.form1.submit();  
            active = 0;
        }
    }

</script>
</head>
<body>
<div class="timer">
    <h1>Welcome to Timertrone.</h1>
    <br>
    <form name='form1' action='' method="post">
        Time left: <input type="text" name="time" id="time" value="">
    </form>
    <span id="msg"></span>
    </br> 
    <button name="start" onclick="startTimer()">Start</button>
    <button name="stop" onclick="stop()">Stop</button>

</div>
</body>
</html>

It only works if I get rid of the // header("Location": update.php?countdown=success");

Share this post


Link to post
Share on other sites

For the benefit of those who cannot see your screen (ie everyone but you) can you descriibe what happens when it "works" and what happens when it "doesn't work"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.