Jump to content

IE7 doesn't work with setting an event.


Lumio

Recommended Posts

Hi!

I list the categories of a web-app of mine with many Dropdown-boxes.

It works great with Firefox and so on. But not with IE.

 

So I do it like this:

<?php //this is javascript
function addCatBox(layer, parent) {
if (parent == 0 && layer == cat_layer) return false;
else if (parent == 0) {
	for (var i=(layer+1); i<=cat_layer; i++) {
		var elm_del = document.getElementById('catDropBox'+i);
		if (typeof elm_del != "undefined" && elm_del != "null")
			document.getElementById('articlepage_create_cat').removeChild(elm_del);
	}
	cat_layer = layer;
	return false;
}
if (layer < cat_layer) {
	for (var i=(layer+1); i<=cat_layer; i++) {
		var elm_del = document.getElementById('catDropBox'+i);
		alert(elm_del);
		if (typeof elm_del != "undefined" && elm_del != "null")
			document.getElementById('articlepage_create_cat').removeChild(elm_del);
	}
	cat_layer = layer;
}

cat_layer++;
makeRequest ('/ajax/article_categories.php?parent='+parent, writeCategories);
}

function writeCategories() {
if (http_request.readyState == 4) {
	if (http_request.status == 200) {
		var xmldoc = http_request.responseXML;
		var cats_node	= xmldoc.getElementsByTagName('categories').item(0);
		var cats_parent	= cats_node.attributes[0].nodeValue;
		var cats		= cats_node.childNodes;
		var elm_cat		= document.getElementById('articlepage_create_cat');

		//some code...

		var newSelection = document.createElement('select');
		newSelection.setAttribute('name', 'catDropBox'+cat_layer);
		newSelection.setAttribute('id', 'catDropBox'+cat_layer);
		//THIS HERE SHOULD CALL THE FUNCTION addCatBox WHEN THE SELECTION
		//CHANGES. IT WORKS ON FIREFOX AND CAMINO AND SO ON
		//BUT _NOT_ ON INTERNET EXPLORER 7
		newSelection.setAttribute('onchange', "addCatBox("+cat_layer+", this.value);");

		//...some code

		var bol_error = false;
		for (var i=0; i<cats.length; i++) {
			if (cats[i].nodeType == 1) {
				if (cats[i].nodeName == 'cat') {
					//... some code that defines cat_id and cat_name

					var newOption	= document.createElement('option');
					newOption.setAttribute('value', cat_id);

					var newOptionVal= document.createTextNode(cat_name);
					newOption.appendChild(newOptionVal);
					newSelection.appendChild(newOption);
				}else if (cats[i].nodeName == 'error') {
					bol_error = true;
					cat_layer--;
					break;
				}
			}
		}
		if (bol_error === false) {
			elm_cat.appendChild(newSelection);
		}
	//... some code
}

}

 

I don't know, why Internet Explorer does not call addCatBox.

Link to comment
Share on other sites

Yes. I already found out, why it didn't work.

I had to add an event with another property. Now this function helped me:

function addEvent(el,ev,fn) {
if(el.addEventListener)
	el.addEventListener(ev,fn,false)
else el.attachEvent('on'+ev, fn)
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.