Presto-X Posted April 25, 2012 Share Posted April 25, 2012 Hello everyone, I paid to get the following script developed because I'm not that great with JavaScript, the script does not seem to work for users using IE7/8 on Win XP. What the script is built to do is countdown X seconds and activate a continue button. The script uses Ajax and PHP to save the logged in user to the database so if they leave the page and come back a few days later the countdown timer will start back where they left off. This script is used for a quiz page, and only logged in users can access it. Here is my page's HTML <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script type="text/javascript"> var userid = "1"; // User ID var quizid = "15"; // Quiz ID var segment = "1"; // Quiz Segment var defaultTime = 3300; // Counter Time In Seconds var updateIntervals = 30000; // Update Database Intervals In Miliseconds </script> <script type="text/javascript" src="components/com_quiz/js/quizTime.js"></script> HERE IS quizTime.js $(document).ready(function() { $.post("components/com_quiz/quizTime.php",{action:"getTime",userID:userid,quizID:quizid,defTime:defaultTime,segmentNum:segment,rand:Math.random()},function(returnTime) { time=parseInt(returnTime); currentTime=time; countDown(time); }); }); //CONVERT SECONDS TO DISPLAY FORMAT function countDown(totalSeconds) { totalSeconds=parseInt(totalSeconds); hours=Math.floor(totalSeconds/3600); hr2=hours%10; hr1=Math.floor(hours/10)%10; minutes=Math.floor((totalSeconds-hours*3600)/60); seconds=totalSeconds-hours*3600-minutes*60; sec2=seconds%10; sec1=Math.floor((seconds/10))%10; min2=minutes%10; min1=Math.floor((minutes/10))%10; $('#h1').html(hr1); $('#h2').html(hr2); $('#m2').html(min2); $('#m1').html(min1); $('#s2').html(sec2); $('#s1').html(sec1); } //UPDATE COUNT DOWN EVERY SECOND setInterval(function() { currentTime--; if(currentTime>=30) { countDown(currentTime); } else { $('#submitDis').hide(); //$('#timeRemaining').hide(); $('#submit').show(); }//DO OTHER STUFF HERE },1000); //UPDATE TIME IN DATABASE EVERY THIRTY SECONDS setInterval(function() { if(currentTime>=0) $.post("components/com_quiz/quizTime.php",{action:"updateTime",userID:userid,quizID:quizid,newTime:currentTime,segmentNum:segment,rand:Math.random()},function(updatedTiming){}); },updateIntervals); HERE IS quizTime.php require_once('config.php'); $con = @mysql_connect($db_host, $db_username, $db_password); @mysql_select_db($db_database, $con); if(isset($_POST['action']) && !empty($_POST['action'])) { $action = $_POST['action']; if($action == "getTime") getTime(); if($action == "updateTime") updateTime(); } function createRecord($userid,$quiz,$time,$segment){ mysql_query("INSERT INTO jos_quiz_user_sessions (userid,quiz,time,segment) VALUES(" . $userid . "," . $quiz . "," . $time . "," . $segment . ")"); } function findValue($userid,$quizid,$segment){ $result = mysql_query("SELECT id FROM jos_quiz_user_sessions WHERE userid = '" . $userid . "' AND quiz = '" . $quizid . "' AND quiz = '" . $segment . "' LIMIT 1;") or die(mysql_error()); $row = mysql_fetch_assoc($result); if($row['id']) return 1; else return 0; } function getTime(){ $userid = $_POST['userID']; $quizid = $_POST['quizID']; $defaultTime = $_POST['defTime']; $segment = $_POST['segmentNum']; if(!findValue($userid,$quizid,$segment)) createRecord($userid,$quizid,$defaultTime,$segment); $result = mysql_query("SELECT time FROM jos_quiz_user_sessions WHERE userid = '" . $userid . "' AND quiz = '" . $quizid . "' AND segment = '" . $segment . "'"); $i = mysql_fetch_row($result); $currentTime = $i[0]; echo $currentTime; } function updateTime(){ $userid = $_POST['userID']; $quizid = $_POST['quizID']; $newTime = $_POST['newTime']; $segment = $_POST['segmentNum']; mysql_query("UPDATE jos_quiz_user_sessions SET time = " . $newTime . " WHERE userid = '" . $userid . "' AND quiz = '" . $quizid . "' AND segment = '" . $segment . "'"); } mysql_close($con); Quote Link to comment https://forums.phpfreaks.com/topic/261600-countdown-timer-not-working-in-ie-do-you-know-why/ Share on other sites More sharing options...
scootstah Posted April 26, 2012 Share Posted April 26, 2012 Any errors? Quote Link to comment https://forums.phpfreaks.com/topic/261600-countdown-timer-not-working-in-ie-do-you-know-why/#findComment-1340556 Share on other sites More sharing options...
Presto-X Posted April 26, 2012 Author Share Posted April 26, 2012 Hello Scott, Thanks for the reply, not sure, we are getting reports from our end users on older systems running XP and IE7 / IE8, I would tell them to upgrade to Firefox or chrome but site owner understandably does not like that idea. Just thought I would post the code up on here and see if anything jumped out at anyone, I'm a PHP guy learning the JavaScript basics. Quote Link to comment https://forums.phpfreaks.com/topic/261600-countdown-timer-not-working-in-ie-do-you-know-why/#findComment-1340603 Share on other sites More sharing options...
scootstah Posted April 26, 2012 Share Posted April 26, 2012 Have you tested it yourself with those browsers? Quote Link to comment https://forums.phpfreaks.com/topic/261600-countdown-timer-not-working-in-ie-do-you-know-why/#findComment-1340631 Share on other sites More sharing options...
Presto-X Posted April 26, 2012 Author Share Posted April 26, 2012 Hello Scott, I do not have XP, but I did test it in IE9 then used IE9's browser mode feature to view it as IE7/IE8 but I dont think that's the same as using IE7 on XP? Quote Link to comment https://forums.phpfreaks.com/topic/261600-countdown-timer-not-working-in-ie-do-you-know-why/#findComment-1340836 Share on other sites More sharing options...
scootstah Posted April 27, 2012 Share Posted April 27, 2012 It's going to be pretty hard to debug without knowing what's wrong. You're pretty much shooting in the dark. Quote Link to comment https://forums.phpfreaks.com/topic/261600-countdown-timer-not-working-in-ie-do-you-know-why/#findComment-1340921 Share on other sites More sharing options...
nogray Posted April 27, 2012 Share Posted April 27, 2012 test with something like this to find the error crossbrowsertesting.com Quote Link to comment https://forums.phpfreaks.com/topic/261600-countdown-timer-not-working-in-ie-do-you-know-why/#findComment-1340949 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.