0

i have a crono app in js but i need to pass that var to a modal in php, i have this (its a embed table)

<table>
    <thead>

    <th>Project</th>
    <th>Task</th>
    <th>Tieme</th>
    <th><th>      
    </thead>
    <tbody>
    <tr>
        <td>".$res[0]."</td>
        <td>".$res[1]."</td>
        <td > <form name='crono' class='large-6'>
    <input type='text' name='face' title='Cronomet'>
    <script type='text/javascript'>
    var timeCrono;

        var hor = 0;
        var min = 0;
        var seg = 0;
        var startTime = new Date();
        var start = startTime.getSeconds();

        var startchron = 0;

        StartCrono();


        function StartCrono() {

          if (startchron == 1) {

            if (seg + 1 > 59) {
                min += 1;
            }
            if (min > 59) {
                min = 0;
                hor += 1;
            }
            var time = new Date();
            if (time.getSeconds() >= start) {
                seg = time.getSeconds() - start;
            }
            else {
                seg = 60 + (time.getSeconds() - start);
            }
            timeCrono = (hor < 10) ? '0' + hor : hor;
            timeCrono += ((min < 10) ? ':0' : ':') + min;
            timeCrono += ((seg < 10) ? ':0' : ':') + seg;
            document.crono.face.value = timeCrono;
            setTimeout('StartCrono()', 1000);
             console.log(timeCrono);

        } 
     }   
    function stopChr() {
       startchron = 0;
     $('#data').text(timeCrono);
    }     

    function startChr() {
        startchron = 1;
        StartCrono();
    } 

    </script>
</form> 

</td>   

        <td><input type='button' id='btnstart'onclick='startChr();' class='button' value='START'></td> 
        <td> <a href='#' data-reveal-id='ventana' id='addhrs'><input type='button' id='btnstop'onclick='stopChr();' class='button' value='STOP'></a></td> 
    </tr>
    </tbody>
</table>";

I need the 'timeCrono' value that is in format 00:00:00, when press the stop button (function stopChr) appear a modal with the info all that i have is the text of that value $('#data').text(timeCrono);

but i need pass that text to a value of a or something like that also #data is a tag <p id='data'></p> and the result that i want is like
<p id='data' value='00:00:00'>.

user3680275
  • 33
  • 1
  • 5

1 Answers1

2

In order to pass values from JavaScript to server-side code, such as PHP, you need to send the value over the network.

Ajax is one of the ways to do that, and jQuery makes it easy to do Ajax queries.

Arseni Mourzenko
  • 50,338
  • 35
  • 112
  • 199