views:

41

answers:

1

Hi, can someone please tell me how to save a javascript rendered countdown timer to mysql db using PHP ? e.g I have this button, that when someone clicks it, the countdown appears and starts counting.

so yeah, that's my problem, what's the best way to do in order to ensure that - the exact date/time(in unix format) the button got clicked will be saved in db? is this possible with PHP ?

// this is the PHP and HTML

<?php foreach($task->result() as $row): ?> 
  <tr> 
    <td><a title="<?php echo $row->descr; ?>" 
           href="#"><?php echo $row->title; ?></a>
    </td> 
    <td><input type = "button" 
       id =<?php echo $row->title; ?> 
       value = "Unlocked" 
       onmouseover = "asktolock(this.id)" 
       onclick = "lockme(this.id)">
    </td> 
    <td><?php echo $row->assign_to; ?></td> 
    <td><a id="txt"></a></td> 
 </tr> 

+1  A: 

Have your button populate a hidden formfield with a timestamp when it is clicked. Set the form to POST to a PHP script which processes the formfields and stores them where you like.

ETA: So on your form you'll need a field like this (with a unique name) for every timestamp you wish to store:

<input type='hidden' name='mytimestamp_unique' id='mytimestamp_unique' value=''/>

And then you'll add some code to your javascript function to set the value of the corresponding "mytimestamp" field. Something like:

function lockme(id){
 //parse the id to get the unique part of the id which is also the unique part of mytimestamp_unique
  var $hiddenfield=getElementById('mytimestamp_' + $uniquepart);
  $hiddenfield.value=new Date().getTime(); 

  //do other lockme stuff

}
dnagirl
the timer is being rendered inbetween the <a></a> tags[code]<td><a id="txt"></a></td>[/code]can you show me a sample snippet ?
sasori
how about you post what you have and I'll see if I can find the bug.
dnagirl
@sasori: I've put your code up in your question. When you want to add code inline, you put backticks \` around it. When you want to add multiline code to a post, use the button that has 101 on it.
dnagirl
should I put the unique stuff inside the "value" attribute of the hidden field ?
sasori
hmmn in your code example`var $hiddenfield=getElementById('mytimestamp_' + $uniquepart);`is javascript allowed to parse a php variable ?
sasori