Results 1 to 8 of 8

Thread: Auto refresh when no value on input box

  1. #1
    Join Date
    Dec 2008
    Location
    Fremont, CA
    Posts
    30
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default Auto refresh when no value on input box

    Hi All,

    I need to refresh the page when there is no data in an input box, basically the input box used is "FCKeditor". When no data on the input box, the page should refresh every fixed/set interval. If data found, the page shouldnt refresh. There are several posts and code snippets on DD, but in my case, they arent help much.

    I would appreciate if somebody could help me out, or give me some pointers that will help me get this resolved.

    Best,
    Kris A

  2. #2
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default

    I think this does what you need.
    Code:
    <html>
    	<head>
    		<script type="text/javascript">
    			//Change these
    			var intervalT = 1000 //Time in milliseconds untill refresh
    			var elementId = "myBox" //ID of text box
    			//Don't change this crap
    			var ele;
    			window.onload = function () {
    				ele = document.getElementById (elementId);
    				setTimeout (function () {
    					if (ele.value == "") {
    						location.reload ();
    					}
    				},intervalT);
    			}
    		</script>
    	</head>
    	<body>
    		<input type="text" id="myBox" />
    	</body>
    </html>
    However, if they type something in and then delete it, the page will not reload. If you want it to, I can do that, but you didn't say it needed to.

    Stephen

  3. #3
    Join Date
    Dec 2008
    Location
    Fremont, CA
    Posts
    30
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default

    Thanks for that, its what i want, while at it a little more tweaking would be great if it aint too much to ask.

    1. A timer
    2. Adding a value and then deleting stops timer , like you have mentioned.

    Best,
    Kris A

  4. #4
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default

    The timer, do you want it to count down? Or what? As for the delete thing. Do you want it to restart if the time is up and then they delete everything? Like this?
    Code:
    <html>
    	<head>
    		<script type="text/javascript">
    			//Change these
    			var intervalT = 1000 //Time in milliseconds untill refresh
    			var elementId = "myBox" //ID of text box
    			//Don't change this crap
    			var ele;
    			var timeup = false;
    			var checkIt = function () {
    				if (timeup) {
    					if (ele.value == "") {
    						location.reload ();
    					}
    				}
    			}
    			window.onload = function () {
    				ele = document.getElementById (elementId);
    				setTimeout (function () {
    					timeup = true;
    					checkIt ();
    				},intervalT);
    				ele.onkeydown = function () {
    					setTimeout (checkIt,0);
    				}
    			}
    		</script>
    	</head>
    	<body>
    		<input type="text" id="myBox" />
    	</body>
    </html>
    So, using this new code. Say you type "hi", wait 5 seconds, then delete it. As soon as you delete the last character, it will reload because the 1 second timer is up.

    Hope this helps,
    Stephen

  5. #5
    Join Date
    Dec 2008
    Location
    Fremont, CA
    Posts
    30
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default

    allrite, i accept i wasnt really precise in what i wanted.

    About the timer: A countdown timer would be ideal, and on timer completion, the page simply should refresh, that is if there is no data in the input box.
    if a value is present in the inputbox, the timer must be frozen so as to not confuse the user.

    Your recent code is perfect for usage, adding a timer would be more of a value add. I appreciate it. Many thanks.

    Best,
    Kris A

  6. #6
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default

    As in, some text that counts down the time? Or should it count up? Should it be in milliseconds or seconds?

  7. The Following User Says Thank You to ??? For This Useful Post:

    l_kris06 (12-31-2008)

  8. #7
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default

    OK. Here's a script with a countdown timer, I don't know if it's what you wanted, and my other script's better, but here you go:
    Code:
    <html>
    	<head>
    		<script type="text/javascript">
    			//Change these
    			var intervalT = 5000; //Time in milliseconds untill refresh
    			var intervalR = 10; //Time in milliseconds untill timer update
    			//WARNING intervalR: A NUMBER TOO SMALL CAN CAUSE LAG, AND TEREFORE CAUSE THE TIMER TO GO SLOWER THAN REAL TIME
    			var displayF = .001; //Amount that the time in milliseconds should be multiplied by before displaying
    			var displayP = 3; //Number of decimal places to be displayed
    			var displayS = " seconds"; //String to be inserted after display
    			var displayId = "displ"; //ID of display element
    			var elementId = "myBox"; //ID of text box
    			//Don't change this crap
    			var disp;
    			var ele;
    			var go = true;
    			var time = intervalT;
    			var inter = intervalT;
    			var toDecimalP = function (num) {
    				var fac = Math.pow (10,displayP);
    				var temp = Math.round (fac * num);
    				return temp / fac;
    			};
    			window.onload = function () {
    				disp = document.getElementById (displayId);
    				ele = document.getElementById (elementId);
    				var inter = setInterval (function () {
    					if (go) {
    						time -= intervalR;
    						if (time <= 0) {
    							location.reload ();
    						}
    					}
    					if (disp.hasChildNodes ()) {
    						disp.removeChild (disp.firstChild);
    					}
    					disp.appendChild (document.createTextNode (toDecimalP (time * displayF) + displayS));
    					
    				},intervalR);
    				ele.onkeydown = function () {
    					setTimeout (function () {
    						if (ele.value == "") {
    							go = true;
    						}
    						else {
    							go = false;
    						}
    					},0);
    				};
    			};
    		</script>
    	</head>
    	<body>
    		<input type="text" id="myBox" />
    		<div id="displ"></div>
    	</body>
    </html>
    Stephen

  9. #8
    Join Date
    Dec 2008
    Location
    Fremont, CA
    Posts
    30
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default

    Hi Stephen,

    Thats great code right there. I like the timer tagged with the ms part.
    Very nice indeed. This is wht i wanted. Many thanks.really appreciate it.

    Best,
    Kris A

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •