milosev.com
  • Home
    • List all categories
    • Sitemap
  • Downloads
    • WebSphere
    • Hitachi902
    • Hospital
    • Kryptonite
    • OCR
    • APK
  • About me
    • Gallery
      • Italy2022
      • Côte d'Azur 2024
    • Curriculum vitae
      • Resume
      • Lebenslauf
    • Social networks
      • Facebook
      • Twitter
      • LinkedIn
      • Xing
      • GitHub
      • Google Maps
      • Sports tracker
    • Adventures planning
  1. You are here:  
  2. Home

setTimeout hell

Details
Written by: Stanko Milosev
Category: JavaScript
Published: 14 June 2013
Last Updated: 25 November 2014
Hits: 5134
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
   <head>
		<title></title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
		
		<script>
			function errorTimeOut(strInTest) {
				alert('I will wait 10 seconds, but no variables (error: Uncaught ReferenceError: strTest is not defined). ' + strInTest)
			}
			
			function errorAlert() {
				var strTest = "I am here!";
				setTimeout("errorTimeOut(strTest)", 10000);
			}
			
			function correctTimeOut(strInTest) {
				alert('I was waiting 20 seconds, and everything is ok: ' + strInTest)
			}

			function correctAlert() {
				var strTest = "I am here!";
				setTimeout(function() {
					correctTimeOut(strTest)
				}, 20000);
			}
		
			setTimeout(alert('I am fired immediately'), 10000);
			
			errorAlert();
			
			correctAlert();
			
		</script>
	
	</head>
	
	<body>

	</body>
   
</html>

As you can see from previous code, setTimeout(alert('I am fired immediately'), 10000); will not work.

setTimeout("alert('I will wait')", 10000); - this will work, alert under quotes, but you can not pass varibles.

And the code:

function correctAlert() {
	var strTest = "I am here!";
	setTimeout(function() {
		correctTimeOut(strTest)
	}, 20000);
}

Will work properly.

Create an array of objects

Details
Written by: Stanko Milosev
Category: JavaScript
Published: 26 August 2012
Last Updated: 26 August 2012
Hits: 4685
var tableProperties = {
    aoColumns: []
};

for (var i = 0; i < 9; ++i) {

    var obj = {
        _origColumnPosition: i
    };
    tableProperties.aoColumns.push(obj);
}

Prototype a string

Details
Written by: Stanko Milosev
Category: JavaScript
Published: 25 August 2012
Last Updated: 25 August 2012
Hits: 4675
    String.prototype.test = function () {
        alert('prototype');
    }

    var a = "";
    a.test();

False is not defined

Details
Written by: Stanko Milosev
Category: JavaScript
Published: 05 August 2012
Last Updated: 27 August 2012
Hits: 5322

In a view if you are receiving error: False is not defined, then you probably have to transfer you variable to low string, something like:

var doAboutTab = @((ViewBag.DoAboutTab != null).ToString().ToLower());

Taken from here

  1. Check members of object
  2. Document.Cookie Property Returns an Empty String
  3. Increasing day and formating date time
  4. Add Single Click Action To A Node In A TreePanel

Subcategories

C#

Azure

ASP.NET

JavaScript

Software Development Philosophy

MS SQL

IBM WebSphere MQ

MySQL

Joomla

Delphi

PHP

Windows

Life

Lazarus

Downloads

Android

CSS

Chrome

HTML

Linux

Eclipse

Page 61 of 168

  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65