Take data from an input

0

I have a chronometer system in which I am trying to take the input data and take it by $_GET to be able to calculate time by value.

var startTime = 0
var start = 0
var end = 0
var diff = 0
var timerID = 0
function chrono(){
	end = new Date()
	diff = end - start
	diff = new Date(diff)
	var msec = diff.getMilliseconds()
	var sec = diff.getSeconds()
	var min = diff.getMinutes()
	var hr = diff.getHours()-diff.getHours()
	if (min < 10){
		min = "0" + min
	}
	if (sec < 10){
		sec = "0" + sec
	}
	if(msec < 10){
		msec = "00" +msec
	} else if(msec < 100){
		msec = "0" +msec
	}
	var time = hr + ":" + min + ":" + sec + ":" + msec
	var inputTime = min + "." + sec
	document.getElementById("chronotime").innerHTML = time
	document.getElementById("chronoInput").value = inputTime
	timerID = setTimeout("chrono()", 10)
}

function chronoStart(){
	document.chronoForm.startstop.value = "Stop"
	document.chronoForm.startstop.onclick = chronoStop
	document.chronoForm.reset.onclick = chronoReset
	start = new Date()
	chrono()
}

function chronoContinue(){
	document.chronoForm.startstop.value = "Stop"
	document.chronoForm.startstop.onclick = chronoStop
	document.chronoForm.reset.onclick = chronoReset
	start = new Date()-diff
	start = new Date(start)
	chrono()
}

function chronoReset(){
	document.getElementById("chronotime").innerHTML = "0:00:00:000"
	start = new Date()
}

function chronoStopReset(){
	document.getElementById("chronotime").innerHTML = "0:00:00:000"
	document.chronoForm.startstop.onclick = chronoStart
}

function chronoStop(){
	document.chronoForm.startstop.value = "Start"
	document.chronoForm.startstop.onclick = chronoContinue
	document.chronoForm.reset.onclick = chronoStopReset
	clearTimeout(timerID)
}
<span class="time" id="chronotime">0:00:00:000</span>
<form name="chronoForm">
<input class="btnStart" type="button" name="startstop" value="Start" onClick="chronoStart()">
<input class="btnReset" type="button" name="reset" value="Reset" onClick="chronoReset()">
</form>
<input class="ress" type="text" name="reported_time" value="" id="chronoInput" step="0.01" min="0.01" required readonly="readonly">

Below the input I'm trying to take the value of it like this:

<?php
$var = $_POST['reported_time'];
?>
<a href="calc.php?tiempo=<?=$var;?>">Calcular</a>

But in calc.php it does not bring me the input data.

    
asked by Stn 04.11.2018 в 00:05
source

1 answer

1

Besides that it is not clear to me how you are sending the data to calc.php , I see two problems. First you are trying to read a JS variable in the PHP code. Second, you are mixing using $ _ POST when in your statement you talk about GET . Taking all this into account, a solution could be to modify the form like this:

        <span class="time" id="chronotime">0:00:00:000</span>
        <form name="chronoForm" action="calc.php" method="get">
            <input class="btnStart" type="button" name="startstop" value="Start" onClick="chronoStart()">
            <input class="btnReset" type="button" name="reset" value="Reset" onClick="chronoReset()">       
            <input class="ress" type="text" name="reported_time" value="" id="chronoInput" step="0.01" min="0.01" required readonly="readonly">
            <input type="submit">
        </form>

and if there was a calc.php file, it would be (the basics) like this:

<?php
   $tiempo = $_GET["reported_time"];
   echo "tiempo=".$tiempo;
?>

I hope it helps.

Greetings,

    
answered by 04.11.2018 / 00:52
source