Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] PHP AJAX and IE disabled option issue


[SOLVED] PHP AJAX and IE disabled option issue

Reply
  #1 (permalink)  
Old 08-19-08, 05:01 PM
Dan Man Dan Man is offline
Newbie Coder
 
Join Date: Sep 2006
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] PHP AJAX and IE disabled option issue

As you may or may not know, adding the "disabled" attribute to an <option> tag in IE does not work. There is a work-around to this using JavaScript that applies a gray-ish style to the option and does not allow the option to be selected, although it can be highlighted.

I am using AJAX to call a PHP page that prints out multiple
HTML Code:
<select> <option disabled>
that are loaded into a div.

The issue is that the JavaScript work-around for IE doesn't work correctly UNLESS I first use an alert() call. That is, the options marked disabled will still be selectable and not gray, but placing the alert() in the code makes it work as intended.

Has anyone ever run across this issue or something similar to it? Why would a call to alert() be the reason that it works? Does alert() do something special in IE that would affect the javascript or html? Is it even the call to alert() or something else?

The code for the javascript work-around is below:

Code:
function disableOptions() {
              if (document.getElementsByTagName) {
		var s = document.getElementsByTagName("select");

		if (s.length > 0) {
			window.select_current = new Array();

			for (var i=0, select; select = s[i]; i++) {
				select.onfocus = function(){ window.select_current[this.id] = this.selectedIndex; }
				select.onchange = function(){ restore(this); }
				emulate(select);
			}
		}
	}
}

function restore(e) {
	if (e.options[e.selectedIndex].disabled) {
		e.selectedIndex = window.select_current[e.id];
	}
}

function emulate(e) {
	for (var i=0, option; option = e.options[i]; i++) {
		if (option.disabled) {
			option.style.color = "graytext";
		}
		else {
			option.style.color = "menutext";
		}
	}
}
The disableOptions function is being called after the php is loaded via AJAX. Placing alert("") as the first line of the disableOptions function fixes the issue.

Any comments and advice welcome.

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 08-26-08, 03:34 PM
Dan Man Dan Man is offline
Newbie Coder
 
Join Date: Sep 2006
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Update: I found no solution to this issue, so as a result, I took a different path of implementation so that disabled options are not required.

I instead displayed only the selectable options within a drop down menu, and dynamically changed the options through JavaScript depending on different conditions. This method accomplished what the disabled options would have.

Thanks to all for taking the time to read and think about this topic.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 08:32 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.