Topic: Checkboxes not Checking in IE7? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=31078" title="Pages that link to Topic: Checkboxes not Checking in IE7? (Page 1 of 1)" rel="nofollow" >Topic: Checkboxes not Checking in IE7? <span class="small">(Page 1 of 1)</span>\

 
Maskkkk
Paranoid (IV) Inmate

From: Johnstown, PA
Insane since: Mar 2002

posted posted 06-26-2009 16:10

Okay I'm totally confused on this one.

I have a script that receives a bunch of values from a JSON object and creates a bunch of checkboxes and either checks or unchecks a these checkboxes based on their values.


This script treats me like a woman treats me...

"If you don't know what's wrong, then I'm not going to tell you..."

The script works correctly in IE8, Firefox3, etc... etc...

However...

In IE7 the script fails to check off the checkboxes. It displays no errors and from what I can tell, the script runs just fine. I just doesn't check any of the checkboxes, and I don't know why...

code:
shoppingCart['Update_Stock_Item_0_NRD%5FHAT2'] = {
				'propeller': {
								'label'          : 'propeller', 							
								'optionValues'   : {													
													 'on' : {
														'selected': 'selected'
															},
													  'off' : {
																'selected': ''
													          },
															'' : new String()
													}
							},
				'sunLogo': {
								'label'          : 'sunLogo', 							
								'optionValues'   : {													
													 'on' : {
														'selected': 'selected'
															},
													  'off' : {
																'selected': ''
													          },
															'' : new String()
													}
							},
				'MSLogo': {
								'label'          : 'sunLogo',
								'optionValues'   : {													
													 'on' : {
														'selected': 'selected'
															},
													  'off' : {
																'selected': ''
													          },
															'' : new String()
													}
							}							
	};



code:
function stockInit() {
		alert("BEGIN: stockInit()");
		// TODO: You will recieve an "on" and an "off" option, 
		//       One will have a "selected" attribute of "selected",
		//       and the other will have a "selected" attribute of ""
		//
		// 		 The option that has the "selected" attribute of "" 
		//		 will generate a checkbox that is not checked.
		//
		// 	     The option that has the "selected attribute of "selected"
		//       will generate a checkbox that is checked.
		//  
		// 		 Why? You ask...because that's just the way the thing is 
		//		                setup.
		for(var item in shoppingCart)
		{
			// // console.log("processing item: " + item);
			
			var optionContainer = document.getElementById(item + "_optionContainer");
		
			for(var option in shoppingCart[item])
			{
				if(option != "blank")
				{
					// // console.log("option: " + option);
			
					var currentOption = shoppingCart[item][option]['optionValues'];
					
					// // console.log("currentOption['on']['selected']: " + currentOption['on']['selected']);
					// // console.log("currentOption['off']['selected']: " + currentOption['off']['selected']);
					
					// Really you only have to check the one, but just to be through-o
					var selected = (currentOption['on']['selected'] == 'selected') ? true : false;
					selected = (currentOption['off']['selected'] == 'selected') ? false : true;
					
					var label = document.createElement("LABEL");
					var labelText = document.createTextNode(shoppingCart[item][option]['label']);
					var optionInput = document.createElement("INPUT");
					
					var hiddenInput = document.createElement("INPUT");
					
					optionInput.setAttribute("type", "checkbox");
					optionInput.checked = selected;
					
					optionInput.setAttribute("id", option);
					alert(optionInput.id);
					alert(optionInput.checked);
					
					hiddenInput.setAttribute("type", "hidden");
					hiddenInput.setAttribute("name", option);
					hiddenInput.setAttribute("id", option + "_hiddenValue");
					hiddenInput.setAttribute("value", (optionInput.checked) ? "on" : "off");
					
					label.appendChild(optionInput);
					label.appendChild(labelText);
					label.appendChild(hiddenInput);
					
					(function(id)
					{
						optionInput.onclick = function() {
							
							var hiddenInput = document.getElementById(id + "_hiddenValue");
							
							hiddenInput.setAttribute("value", (this.checked == true) ? "on" : "off");
							alert("this.id: " + this.id);
							alert("this.checked: " + this.checked);
						}
					})(optionInput.id);
					
					optionContainer.appendChild(label);
										
					
				}
			}
			// // console.log("processing item of " + item + " complete");
		}
		alert("END: stockInit()");
	}



And please don't ask why I'm doing things this way...all I can really tell you is that I don't have access to the backend code...so I get what I get...



- AIM: MASKKKK

01001101011000010111001101101011011010110110101101101011


(Edited by Maskkkk on 06-26-2009 16:14)

(Edited by Maskkkk on 06-26-2009 16:14)

Maskkkk
Paranoid (IV) Inmate

From: Johnstown, PA
Insane since: Mar 2002

posted posted 06-26-2009 17:05

Okay nevermind, found it...

It was some insanely obscure reference...

code:
optionInput.defaultChecked



Or alternatively...set it as checked after it's been added to the DOM.



- AIM: MASKKKK

01001101011000010111001101101011011010110110101101101011

akloid
Neurotic (0) Inmate
Newly admitted

From:
Insane since: Sep 2009

posted posted 09-05-2009 11:10

deleted, sorry.

(Edited by akloid on 09-05-2009 11:13)

akloid
Obsessive-Compulsive (I) Inmate

From:
Insane since: Sep 2009

posted posted 09-05-2009 11:13

Why not to use IE8 in IE7 mode with javascript debugger? It will help you to solve most problems with js.

http://fileroad.com

coach
Nervous Wreck (II) Inmate

From:
Insane since: May 2011

posted posted 05-31-2011 11:07
Edit TP: spam removed


Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu