JavaScript - Page Refreshes Before Timer Has Done It's Job...
I'm just trying to make a simple interface.
On the html form the user enters the time to start, time to end, and frequency of a reminder alert. I pass this to my javascript and then am trying to setup a 1 second loop where it checks against the clock to see if it's time to begin the reminders. I get to the function, but the setTimeout doesn't complete and my page just refreshes. Here's my javascript code for this section.... Code: //-----------Start Countdown--------------------------- function StartCountDown(startTime, endTime, freq){ now=new Date(); intToStart=startTime-now; intInSec=intToStart/1000; alert(intInSec + " sec"); if (now > startTime){ StartRepeat(endTime, Freq); } else{ var TTS=setTimeout("StartCountDown(startTime, endTime, freq);", 1000); } } function StartRepeat(endTime, freq){alert("Made it to StartRepeat Function"); if (freq != 0){ var task=setInterval("TaskRemind(endTime, freq)", freq); } else{ clearTimeout(task); } } function TaskRemind(endTime, freq){ alert("Do Task Now!"); now=new Date(); if (now <= endTime){ StartRepeat(endTime, freq); } else{ freq=0; StartRepeat(endTime, freq); } } Any help is greatly appreciated. Brian Similar TutorialsYou know how google has different ads everytime you go to a page? Well i want to do the same thing. I got two banners and i want one to change to the other banner when someone refreshes the page.
I'm poking in the blind with javascript and hope that you can help with this issue. A javascript function is making a call to an external php file, which checks the compares the current time with a time stored in a mysql database. If a certain time passes, the php will send back instructions to redirect the user to a different page. The issue is that the page refreshes every time the is javascript function is executed. This resets any forms, or videos that the user is watching on the page. Here is the relevant code: Code: function checkTimer() { if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { window.location.href = xmlhttp.responseText; } } xmlhttp.open("POST","php/5minforpage10.php",true); xmlhttp.send(); } window.setInterval(checkTimer,15000); Is there a way to achieve the goal of checking the time against the server time (via the php code) without refreshing the page? Thanks kindly! Hi All, Im new to this forum...need some of your help and advice. I have a js code like this : <script type="text/javascript"> <!-- var sipPos = 0; $(document).ready(function() { $("#panel-tab").click(function(e) { //if(autoTimer) clearTimeout(autoTimer); //autoTimer = null; e.preventDefault(); $("#panel").animate({ left: sipPos }, 1764, 'linear', function() { if(sipPos == 0) { sipPos = -856; } else { sipPos = 0; } }); }); }); --> </script> what it does is that it hide and show a panel by slidint it to the left. But my client want that on page load the panel opens automatically for about 2-3 seconds just to let users know that its here. So ive written this : <script type="text/javascript"> <!-- var sipPos = 0; $(document).ready(function() { var autoTimer = null; autoTimer = setTimeout(function(){ $("#panel").animate({ left: sipPos }); autoTimer = setTimeout(function(){ $("#panel").animate({ left: sipPos = -856 }); }, 2000); },1000); $("#panel-tab").click(function(e) { //if(autoTimer) clearTimeout(autoTimer); //autoTimer = null; e.preventDefault(); $("#panel").animate({ left: sipPos }, 1764, 'linear', function() { if(sipPos == 0) { sipPos = -856; } else { sipPos = 0; } }); }); }); --> </script> But when the panel finished showing the button to open it again doesn't work...any help please..really urgent. thks //Sam I would like to know a script for when you have a page that can expire (or cannot be open again) --- a time limit for like 24 hours. Because I'm going to make a site where people can buy website designs, they buy it off paypal, they get redirected to a site where the code is located and the site will get expired in 24 hours -- then, they wouldn't be able to open the page again. If anyone knows the script, please post it here! Thank you x Sorry for the title- i'm doing my best to describe my problem. So this is basically it: I have some javascript onmouseover events that change the content of an iframe. The problem is that within the javascript calls, I have some url's attached to rollover buttons INSIDE the parent div's that are being manipulated by javascript. So the iframe refreshes properly when its supposed to, but it ALSO refreshes as each of the links inside the effected div are rolled over as well. So there is too much extra refreshing and lots of clicking noises because of the Internet Explorer default noise settings. The easiest way to see what im talking about is to go to: http://maybetheworldisending.com/fre...HOMEPAGE_jan4/ An example of the problematic code is as follows: Code: <div class="beachcomberoff" target="mainbox" onmouseover="ShowPage('frame1_slider');this.className='beachcomberon'" onmouseout="this.className='beachcomberoff';"> <div id="turquoise1"><a href="#"></a></div><div id="coral1"><a href="#"></a></div><img src="HOMEPAGE_jan4_web/beachcomber.png" width="453" height="330" border="0"></div> The prob is that the div's named turquoise1 and coral1 are being effected by the javascript on the containing div. How do i make it unaffected by that js? Is there something like a "onmouseover=do nothing" or something of the sort? How could I lock an "Enter" link on an intro page with a 30 second timer that is displayed on the bottom of the page and disables the "Enter" link so that visitors have to wait 30 seconds to read the rules/announcements before entering?
I'm trying to build a time but it isn't displaying on screen Code: <html> <head> <script type="text/javascript"> function StartCounting(){ setInterval("DoCounting()", 1000) } function DoCounting(){ var obj =getElementbyId('countingtext'); obj.innerHTML = '' + Counter; Counter++; if( Counter > 10) { Counter = 0; document.writeln("Timer Reset"); } } </script> </head> <body onload= "StartCounting()"> Here it is:<span id="countingtext"></span> </body> </html> Alright, im trying for my project to make 1 div scroll through a list of pictures. I have it so that it starts when I click the button. Now what im trying to do is after I start the timer I have the button changing values to 'Pause' instead of 'Start' but I can't figure out how to code to make the timer pause when i click the button again. Code: HTML: <input id="timer" style="position: absolute; font-size: 50px; background-color: red; top:750px;left: 800px; height: 75px; width: 120px;" type="button" value="Start" onclick="myTimer = setInterval('picture()', 2000); document.getElementById('timer').value = 'Pause';"> Code: Javascript: function picture() { soccerImg.src = soccerPic[state]; state++; if(state == 35) { state = 0; } } Hi I am working on a chat application and am a bit stuck...In the database I have a field status which is set 1 for online and 0 for offline (PHP/MySQL)(at time of logging in/out), this shows the users status on a webpage. What I need is to know if there is a way I can set a timer so that if the user has been inactive for X amount of time, the database is auto updated and user is offline (1 set to 0). Thanks for any help I recieve index.php Code: <a href="#" onClick="getTimer();return false;">Show Timer</a> <br /> <div id="test"></div> getTimer.js Code: function getTimer() { new Ajax.Request('filegoeshere', { onSuccess: function(req) {eval(req.responseText);}, onFailu function(){ alert('Something went wrong...') } }); } timer.php Code: <?php echo "$('test').innerHTML = '<form><input type=\"text\" name=\"timer\" id=\"timer\" size=\"8\" style=\"text-align: center;\" /></form>';"; ?> var seconds= 30 $('timer').value='30' function display() { seconds--; if (seconds<=-1){ seconds=30 } else $('timer').value=seconds; setTimeout("display()",1000) } display() Everything seems to work, but the once the timer is in the input box, after the request, it get's stuck on 29, and will not continue counting down, and I can't seem to get it to work. I am using ProtoType with this, and I did just take that little part out of the index.php file, since that is all that is needed from that file. Hello, I'm on a RPG game and they have a automatic logout timer to stop people from using bots to play, the only problem with it is, if someone lets the timer run out, it won't let the user log back in for a time (This time could be anywhere from 5 minutes to 3 hours from what other members have told me) Now java isn't my strong point (But I'm learning ^_^) and I'm not 100% sure if this error is related to java or some other code format. Using the develop tool in Safari I was able to find the code, and its telling me thats its java, I'm sorry if this is in the wrong place if its not Java after all. I'm wondering if looking over this code, someone might be able to find the problem or might have any tips to make it work better. (Note; I'm not the admin or owner of the RPG, but the owner hasnt done anything about it mainly cause they are to lazy I think?? or might not know how to fix it. PHP Code: var c_reloadwidth3=200 var countDownTime3=countDownInterval3+1; function countDown3(){ countDownTime3--; if (countDownTime3 <=0){ countDownTime3=countDownInterval3; clearTimeout(counter3) window.location.reload() return } if (document.all) //if IE 4+ document.all.countDownText3.innerText = Math.floor(countDownTime3 / 60)+":"+(countDownTime3 % 60)+" "; else if (document.getElementById) //else if NS6+ document.getElementById("countDownText3").innerHTML= Math.floor(countDownTime3 / 60)+":"+(countDownTime3 % 60)+" " else if (document.layers){ document.c_reload.document.c_reload3.document.write('<b id="countDownText3">'+countDownTime3+' </b>') document.c_reload.document.c_reload3.document.close() } counter3=setTimeout("countDown3()", 1000); } function startit3(){ if (document.all||document.getElementById) document.write('<b id="countDownText3">'+countDownTime3+' </b>') countDown3() } For all I know it could be another script causing it to do it, but this is a start to help try and fix the problem. Thank you to anyone who helps. - zerobeat, Jack. Hi guys, I'm building a page which has a countdown timer on it (days, hours, mins) and I honestly really don't know much about Javascript at all. I have spent over half a day looking through tutorials and code snippets and think I'm close, but I'm still having trouble with the output. I need to pull out the days/hours/mins separately as they sit within different HTML elements. The days appear to be displaying correctly, but the hours is showing 3 digits instead of 2 and the mins is showing 5 digits instead of 2: 32 days, 764 hours, 45845 mins Here is the code I'm using: Code: var now = new Date(); var theevent = new Date("June 18 2011 10:00:00"); var seconds = (theevent - now) / 1000; var mins = seconds / 60; var hours = mins / 60; var days = hours / 24; ID=window.setTimeout("update();", 1000); function update() { now = new Date(); seconds = (theevent - now) / 1000; seconds = Math.round(seconds); mins = seconds / 60; mins = Math.round(mins); hours = mins / 60; hours = Math.round(hours); days = hours / 24; days = Math.round(days); document.getElementById('days').innerHTML = days; document.getElementById('hours').innerHTML = hours; document.getElementById('mins').innerHTML = mins; ID=window.setTimeout("update();",1000); } Thanks a bunch in advance... hi, i am currently trying to write a javascript program; it would be for a library reservation system. this would be put on the computers with sessions from 15 minutes to 2 hours (in 15 minute chunks i.e, 15, 30, 45, 1 hour). this program would countdown the remaining time on their session, with pop-up messages appearing every so often. at the end of the session, the program will have to automatically log the user off. i am a student studying javascript, and haven't got any idea how to even start can anyone give me a helping hand to get me started. thanks Hi All, I am trying to set up a countdown function that will be called on the click of a button. Function is below Code: function countDown(sec, min) { sec--; if (sec == -01) { sec = 59; min = min - 1; } else { min = min; } if (sec<=9) { sec = "0" + sec; } time = (min<=9 ? "0" + min : min) + " min and " + sec + " sec "; if (document.getElementById) { theTime.innerHTML = time; } SD=window.setTimeout("countDown();", 1000); if (min == '00' && sec == '00') { sec = "00"; window.clearTimeout(SD); } } function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { if (oldonload) { oldonload(); } func(); } } } addLoadEvent(function() { }); However I get an error after one second. Script can be found here - http://www.jivalot.co.uk/m.php Can anyone help? Kind regards, Slate Hi people, Im really stuck, I have a script I want to load when my page opens, I can et it to do this fine, but I want to be able to input a delay time, any time I want. So my page loads, 1,2,3,4,5 then my script kicks in. I have searched hi and low, but my understanding with JS is very basic, but I am willing myself to learn. Thank you very much in advance for your help. Bev hi guys, ive found the code for the perfect timer but cant for the life of me find the part to change the date to count down from. can anyone point it out? heres the code. <script language="JavaScript"> var countDownInterval=5; var countDownTime=countDownInterval+1; function countDown(){ countDownTime--; if (countDownTime <=0){ countDownTime=countDownInterval; clearTimeout(counter) window.location="file:///E:/................html"; return } if (document.all) //if IE 4+ document.all.countDownText.innerText = countDownTime+" "; else if (document.getElementById) //else if NS6+ document.getElementById("countDownText").innerHTML=countDownTime+" " else if (document.layers){ document.c_reload.document.c_reload2.document.write('WEDDING DAY IN... <b id="countDownText">'+countDownTime+'</b> minutes') </b> seconds') document.c_reload.document.c_reload2.document.close() } counter=setTimeout("countDown()", 1000); } function startit(){ if (document.all||document.getElementById) document.write('WEDDING DAY IN... <b id="countDownText">'+countDownTime+' </b> seconds') countDown() } if (document.all||document.getElementById) startit() else window.onload=startit setTimeout("location.href='http://www.wallpaperama.com'" , t) </script> Hello, i need one script, which will remove the timer and i’ll be able to start download the file without waiting the time… Okay, i dont need such things… I need only one simple thing… Without any premium accounts… It should remove the timer (30 sec)… That’s everything i want… Link: *HIDEN* Thanks. Contact me via pm or skype - bahurz1 hi , im newbie here and need some help from all the guru here , can some 1 help me out with iframe , i want an iframe can do auto reload on list sites after specific time , example after 10 seconds ifram will open google.com and after 10 seconds again iframe will reload yahoo.com and so on. please some one help me , i had try to search on google and others but still can find it , i apreciate all the help thank you Hi everyone, I need a countdown timer that will count down exactly from a time that i set. i want it to count in this format: hh:mm:ss. i need it for a online shop , at the main page there are few products for sell and i want each one of them to have its own countdown timer. in addition when it will get to 00:00:00 i want that it will automatically add like 5 hours and continue counting down.. P.s i dont know javascript.. thanks guys Hi everyone I need a function which will record the amount of time that a window has been open for. Upon load, the function should start a timer, and upon close, the function should store the number of minutes and seconds to a field on the form called 'Time'. My concern with this is whether you can write to a DOM element upon closre of a window, or whether we loose that ability as soon as the close event happens? if you could help priovide ideas around doing this then I'd be very grateful Dom |