suttercain Posted June 11, 2007 Share Posted June 11, 2007 Hi guys, This is more of a PHP question than a JavaScript question. I am sure someone out there has had to do this before. I have a form which is actually a stopwatch: <form name="timeform" method="post"> Time: <input type=text name="timetextarea" value="00:00" size="10" style = "font-size:20px"> Lap: <input type=text name="laptime" size="10" style = "font-size:20px"><br> <br> <input type=button name="start" value="Start/Lap" onclick="sw_start()"> <input type=button name="stop" value="Stop" onclick="Stop()"> <input type=button name="reset" value="Reset" onclick="Reset()"> </form> I need to get it so the stop time, onclick="Stop()" is converted into $_POST['stop'] The thing is I already have a get method used to reload the page. A quick explanation. I am trying to measure the time of certain phone calls. I hit the stopwatch when a call comes in. Let's say the call is 3 minutes. I click stop() and now have 3:00 displayed in the form. I then click a link (echo "<a href=\"?id=".$row['typeId']."\">".$row['type']."</a>" based on the type of call it was. The type of call, operator and id are entered into the database and the page reloads. I would also like to get the stop time into the database so I know how long the call lasted. Is it possible? Here is the entire code: <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Daily Phone Log</title> <?php require_once ('get_connected.php'); ?> <style type="text/css"> @import url("phonecalls.css"); </style> <script language="JavaScript"> <!-- var timercount = 0; var timestart = null; function showtimer() { if(timercount) { clearTimeout(timercount); clockID = 0; } if(!timestart){ timestart = new Date(); } var timeend = new Date(); var timedifference = timeend.getTime() - timestart.getTime(); timeend.setTime(timedifference); var minutes_passed = timeend.getMinutes(); if(minutes_passed <10){ minutes_passed = "0" + minutes_passed; } var seconds_passed = timeend.getSeconds(); if(seconds_passed <10){ seconds_passed = "0" + seconds_passed; } document.timeform.timetextarea.value = minutes_passed + ":" + seconds_passed; timercount = setTimeout("showtimer()", 1000); } function sw_start(){ if(!timercount){ timestart = new Date(); document.timeform.timetextarea.value = "00:00"; document.timeform.laptime.value = ""; timercount = setTimeout("showtimer()", 1000); } else{ var timeend = new Date(); var timedifference = timeend.getTime() - timestart.getTime(); timeend.setTime(timedifference); var minutes_passed = timeend.getMinutes(); if(minutes_passed <10){ minutes_passed = "0" + minutes_passed; } var seconds_passed = timeend.getSeconds(); if(seconds_passed <10){ seconds_passed = "0" + seconds_passed; } var milliseconds_passed = timeend.getMilliseconds(); if(milliseconds_passed <10){ milliseconds_passed = "00" + milliseconds_passed; } else if(milliseconds_passed <100){ milliseconds_passed = "0" + milliseconds_passed; } document.timeform.laptime.value = minutes_passed + ":" + seconds_passed + "." + milliseconds_passed; } } function Stop() { if(timercount) { clearTimeout(timercount); timercount = 0; var timeend = new Date(); var timedifference = timeend.getTime() - timestart.getTime(); timeend.setTime(timedifference); var minutes_passed = timeend.getMinutes(); if(minutes_passed <10){ minutes_passed = "0" + minutes_passed; } var seconds_passed = timeend.getSeconds(); if(seconds_passed <10){ seconds_passed = "0" + seconds_passed; } var milliseconds_passed = timeend.getMilliseconds(); if(milliseconds_passed <10){ milliseconds_passed = "00" + milliseconds_passed; } else if(milliseconds_passed <100){ milliseconds_passed = "0" + milliseconds_passed; } document.timeform.timetextarea.value = minutes_passed + ":" + seconds_passed + "." + milliseconds_passed; } timestart = null; } function Reset() { timestart = null; document.timeform.timetextarea.value = "00:00"; document.timeform.laptime.value = ""; } //--> </script> </head> <div id="main"> <?php //Verifiy authorization to view page if ($_SESSION['permission'] == 1) { $pw = $_SESSION['pw']; $user = $_SESSION['user']; $operatorId = $_SESSION['operatorId']; ?> <div id="header"> <div id="logo"></div> <div id="topmenu"><?php echo "Logged in as " .strtoupper($user). " "?>| LOG OUT</div> </div> <body> <div id="bottomborder"> <?php //Populate phone call type from database $results = mysql_query("SELECT * FROM typeOfCalls ORDER BY type") or die(mysql_error()); echo "<div class=\"left\">"; while ($row=mysql_fetch_assoc($results)) { echo "<a href=\"?id=".$row['typeId']."\">".$row['type']."</a>"; echo "<br />"; $rows[$row['typeId']] = $row['type']; } echo "</div></div>"; //If a phonce call type is clicked, add it to the database if (isset($_GET['id'])) { $timer = $_POST['Stop']; echo "Timer: $timer <br>"; $date = date('Y-m-d'); global $date; $time = date('H:i:s'); $sql = "INSERT INTO totalCalls (typeId, dateInfo, timeInfo, operatorId) VALUES ('".mysql_real_escape_string($_GET['id'])."', '$date', '$time', '$operatorId')"; $into = mysql_query($sql) or die(mysql_error()); //If call added echo as such if ($into) { $time = date('g:ia'); echo "<div id=\"lastcall\">" .$rows[$_GET['id']]. " call added at $time</div>"; } } //Get Statistics for Operator $stats = mysql_query("SELECT * FROM totalCalls WHERE operatorId = '".$operatorId."' AND dateInfo ='".$date."'") or die(mysql_error()); $morestats = mysql_query("SELECT *, COUNT(tc.typeId) AS numcall FROM totalCalls AS tc LEFT JOIN typeOfCalls AS toc ON toc.typeId = tc.typeId WHERE tc.operatorId = '".$operatorId."' AND tc.dateInfo ='".$date."' GROUP BY tc.typeId ORDER BY type") or die(mysql_error()); $total = mysql_num_rows($stats); echo "<div id=\"rightborder\">"; echo "<div class=\"right\">"; echo "Total Calls Answered Today: $total"; echo "<table width=\"400\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"; while ($row = mysql_fetch_array($morestats)) { $rowz = $row["numcall"]; echo "<tr>"; echo "<td width='250'>" .$row['type']. "</td>"; echo "<td>$rowz</td>"; echo "</tr>"; } echo "</table>"; echo "</div></div>"; } //If person is NOT authorized else { echo "Access Denied!"; } ?> <form name="timeform" method="post"> Time: <input type=text name="timetextarea" value="00:00" size="10" style = "font-size:20px"> Lap: <input type=text name="laptime" size="10" style = "font-size:20px"><br> <br> <input type=button name="start" value="Start/Lap" onclick="sw_start()"> <input type=button name="stop" value="Stop" onclick="Stop()"> <input type=button name="reset" value="Reset" onclick="Reset()"> </form> </div> </body> </html> Thanks for the advice! SC Link to comment https://forums.phpfreaks.com/topic/55124-javascript-into-a-php-variable/ Share on other sites More sharing options...
lighton Posted June 12, 2007 Share Posted June 12, 2007 regarding the post['stop'] in the stop function have your javascript append a hidden form input to the form with the time value. Link to comment https://forums.phpfreaks.com/topic/55124-javascript-into-a-php-variable/#findComment-273017 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.