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
  3. JavaScript

Document.Cookie Property Returns an Empty String

Details
Written by: Stanko Milosev
Category: JavaScript
Published: 02 February 2009
Last Updated: 15 August 2012
Hits: 5532

This took me some time:

 

When you use client-side code (the Document.Cookie property) to write cookies, and then use the same method to retrieve the cookies, you may receive an empty string or the following error message:

 
ERROR_INSUFFICIENT_BUFFER
 
From here.
 
So, I guess, better don't use JavaScript setcookie, rather use server - side setting cookies.

Increasing day and formating date time

Details
Written by: Stanko Milosev
Category: JavaScript
Published: 28 January 2009
Last Updated: 08 July 2013
Hits: 5257

First, code for increasing day. If we have date in string, then code would look something like this:

strYear = strDate.substring(0,4);
strMonth = strDate.substring(5,7);
strDay = strDate.substring(8,10);
d = new Date(strYear, strMonth - 1, strDay);
d.setDate(d.getDate() + 1);

Then, to format date time, to something like yyyy-mm-dd, I was using this code:

strYear = d.getFullYear();
if (d.getMonth() < 10)  {  
	intMonth = d.getMonth() + 1;
	strMonth = '0' + intMonth;
} else  {
  strMonth = d.getMonth() + 1;
}
if (d.getDate() < 10)  {
  strDay = '0' + d.getDate();
} else {  
	strDay = d.getDate();   
}

Finnaly, date would be created something like:

strDate = strYear + '-' + strMonth + '-' + strDay;

getMonth - with this function we are geting number of a month, but from 0, 0 - this is January?
getDate - with this function we are geting number of a day in a month.

Add Single Click Action To A Node In A TreePanel

Details
Written by: Stanko Milosev
Category: ExtJS
Published: 12 May 2011
Last Updated: 26 August 2012
Hits: 5023
    var tree = Ext.create('Ext.tree.Panel', {
        store: store,
        hideHeaders: true,
        rootVisible: false,
        viewConfig: {
            plugins: [{
                ptype: 'treeviewdragdrop'
            }]
        },
        height: 450,
        width: 400,
        title: 'InLabel server and databases',
        renderTo: 'tree-example',
        collapsible: true,
	listeners:{
		itemclick: function(view, record, item, index, event) {
			if (record.isLeaf()) {
				Ext.fly("yourdivid").update(record.data.text);
			} else {
				Ext.Ajax.request({
				    url: 'components/com_dcstree/detailed_info.php',
					method: 'GET',
				    params: {
					id: record.data.id
				    },
				    success: function(response){
					var text = response.responseText;
					Ext.fly("yourdivid").update(text);
					// process server response here
				    }
				});
			}
			//Ext.get("yourdivid").originalDisplay = "aaa";
			//dumpProps(view);
		}
	}
    });

So, most important thing is "listeners", and with record.isLeaf() I am checking if user clicked on node, or on leaf. Second part, Ext.Ajax.request,... is example of ExtJS Ajax, in this case I am loading detailed_info.php.

Attach event on dynamically added HTML

Details
Written by: Stanko Milosev
Category: jQuery
Published: 30 May 2019
Last Updated: 30 May 2019
Hits: 2741
Use the jQuery on() method.

Example:

HTML:

<!DOCTYPE html>
<html>
	<head>
		<script type="text/javascript" src="lib/jquery-3.4.1.min.js" defer></script>
		<script type="text/javascript" src="js/index.js" defer></script>
	</head>
	<body>
		<div id="append"></div>
	</body>
</html>

JS:

$('#append').append('<a href="#" class="apendTest">Test</a>');
$('#append').on('click', '.apendTest', function() {
	alert("test")
})
  1. Infinite slider
  2. Inline images
  3. jQuery animation
  4. Don't loose focus

Subcategories

Ajax

JavaScript

ExtJS


jQuery

Bing Maps AJAX Control, Version 7.0

Knockout

Jasmine

Moment

node.js

Page 9 of 24

  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13