Jump to content

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?



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);

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


<style type="text/css">
    div.timer {
        text-align: center;
        margin: 15% auto;
    #msg {
        color: red;
<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?> ;
        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;
        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() {
        }, 1000);

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

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


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.