| Subcribe via RSS

checkbox select all function

February 7th, 2008 | 1 Comment | Posted in javascript by dreamluverz

I created some function for selectall checkbox. It works coz i’ve been using this.



obj_chkall - is the object of the checkbox that when you click will check all other checkboxes usually on mails
chkbox_name - is the name of the field of the checkboxes

function dps_chkall(obj_chkall, chkbox_name){
var form_name = obj_chkall.form;

if(typeof(chkbox_name) == 'object'){
obj_chkall.checked = false;
}else{
for(var d = 0; d < form_name.elements.length; d++){
if(form_name.elements[d].name == chkbox_name){
form_name.elements[d].checked = obj_chkall.checked;
}
}
}
}

Tags: , ,

window.opener.location.reload()

January 8th, 2008 | No Comments | Posted in javascript by dreamluverz


I got main window and a pop up and wanted to reload the main window through the popup with window.opener.reload(). I got an error saying IT’S NOT A FUNCTION. I checked the code several times of other possible issues that may have caused it. I know I got it right ‘coz i’ve done it before but why I can’t do it again?!?! I tried checking google for opener.reload(). But still I can’t get it right. This time I tried the keyword reload() property in javascript. Damn!!! I missed one property, the location. It should have been window.opener.location.reload().

Now keep that in mind :P

Tags: ,

simple example of using json

December 13th, 2007 | No Comments | Posted in ajax, javascript by dreamluverz

Assuming that this array is the return value of ajax and already been evaluated to json.
This is the link on how to do it http://dreamluverz.com/2007/12/12/ajax-and-json/

The {} and [] symbolizes for array

“key” : “value” => ‘:’ colon separates the key and value

var a = {"ids" :[
{"id" : "1", "name" :
["a", "b"]
},
{”id” : “2″, “name” :
[ "ab"]
}
]}

for(var d=0; d < a.ids.length; d++){
alert(a.ids[d].id);
for(var p=0; p < a.ids[d].name.length; p++){
alert(a.ids[d].name[p]);
}
}

Imagine that array in this way using php:

$ids[0]['id'] = 1;
$ids[0]['name'] = array(”a”, “b”);

$ids[1]['id'] = 2;
$ids[1]['name'] = array(”a”);

Tags:

ajax and json

December 12th, 2007 | No Comments | Posted in ajax, javascript, xml by dreamluverz

 JSON

The third method is JSON, JavaScript Object Notation. Personally I pronounce it as “Jason”, so that yet another ancient Greek hero enters modern JavaScript development. (And please remember that Ajax’s father Telamon accompanied Jason as an Argonaut. Jason was older, and on the whole more succesful, than Ajax)

The general idea is to deliver a bit of text (a string, really) which can be interpreted as a JavaScript object. Once it has arrived, you use JavaScript’s eval() method to convert the string into a real JavaScript object, which you then read out.

Example

The server returns this JSON string:

{"books":[{"book":
		{
		"title":"JavaScript, the Definitive Guide",
		"publisher":"O'Reilly",
		"author":"David Flanagan",
		"cover":"/images/cover_defguide.jpg",
		"blurb":"Lorem ipsum dolor sit amet, consectetuer adipiscing elit."
		}
	},
	{"book":
		{
		"title":"DOM Scripting",
		"publisher":"Friends of Ed",
		"author":"Jeremy Keith",
		"cover":"/images/cover_domscripting.jpg",
		"blurb":"Praesent et diam a ligula facilisis venenatis."
		}
	},
	{"book":
		{
		"title":"DHTML Utopia: Modern Web Design using JavaScript & DOM",
		"publisher":"Sitepoint",
		"author":"Stuart Langridge",
		"cover":"/images/cover_utopia.jpg",
		"blurb":"Lorem ipsum dolor sit amet, consectetuer adipiscing elit."
		}
	}
]}

The script looks rather a lot like the XML script. It does the same things, it just reads out the data from another format. Here, too, XSLT might come in handy.

function setDataJSON(req)
{
	var data = eval('(' + req.responseText + ')');
	for (var i=0;i<data.books.length;i++)
	{
		var x = document.createElement('div');
		x.className = 'book';
		var y = document.createElement('h3');
		y.appendChild(document.createTextNode(data.books[i].book.title));
		x.appendChild(y);
		var z = document.createElement('p');
		z.className = 'moreInfo';
		z.appendChild(document.createTextNode('By ' + data.books[i].book.author + ', ' + data.books[i].book.publisher));
		x.appendChild(z);
		var a = document.createElement('img');
		a.src = data.books[i].book.cover;
		x.appendChild(a);
		var b = document.createElement('p');
		b.appendChild(document.createTextNode(data.books[i].book.blurb));
		x.appendChild(b);
		document.getElementById('writeroot').appendChild(x);
	}
}

 

Advantages

The most important advantage is that JSON circumvents JavaScript’s same-source policy, if you import the JSON file as a new <script> tag. See Simon Willison’s example for the gory details.

JavaScript does not allow you to access documents (be they XML or HTML) that come from another server. However, if you import a JSON file as a script tag you circumvent this problem, and any JSON data can be imported into any website. It depends on your business goals whether this is a Good or a Bad Thing, but right now it’s the only data format that allows unrestricted access.

A secondary advantage is that scripts for JSON data are slightly simpler and slightly more in line with the rest of the JavaScript language than scripts for XML data.

Disadvantages

The most important disadvantage of JSON is that the format is very hard to read for humans, and that, of course, every single comma, quote, and bracket should be in exactly the correct place. While this is also true of XML, JSON’s welter of complicated-looking syntax, like the }}]} at the end of the data snippet, may frighten the newbies and make for complicated debugging.

sources: http://www.quirksmode.org/blog/archives/2005/12/the_ajax_respon.html

http://www.developer.com/lang/jscript/article.php/3596836

Tags: , , ,

javascrpt function setHomePage doesn’t work with firefox and ie

December 1st, 2007 | No Comments | Posted in javascript by dreamluverz

We need to use this javascript function setHomePage() for our website but my teammate said it only works for ie. So I did some checking on that function and bumped into different sites that referenced it.  And some are listed below.

references:

http://www.experts-exchange.com/Software/Internet_Email/Web_Browsers/Q_22761088.html

http://www.boutell.com/newfaq/creating/sethomepage.html

Anyways, if you have any idea or workaround for this let us know we would be very glad to know it. Thanks in advance.

Tags: , , ,