Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkbox can't be enabled?

Status
Not open for further replies.

NBartomeli

Programmer
Jul 1, 2003
111
US
I have an ASP page which uses javascript for some validation and other things. I have a routine which fills text boxes with values when they are dragged over, and when text is entered in the box, I want the checkbox that corresponds with that text box to become enabled (they are all disabled by default).

I have something like this for the checkbox

Code:
<ASP:CheckBox ID="chkColL1" Enabled="False"/>

and my javascript to enable the checkbox looks like:
Code:
//elemArray[6] is the ClientID of the checkbox
document.forms[0][elemArray[6]].disabled = false;

I know this should work, because if I ENABLE all of the checkboxes by default, and set disabled=true when the text is changed, they work fine.

When i step through in the debugger, the value shows disabled = false (AKA they should be ENABLED) but the changes are not reflected in the control on the page.

This is probably something simple, but its driving me nuts. Any help would be appreciated. Thanks in advance

 
Thats throws an error.

The code as I had it works, just does not reflect on the page. If I drop to the debugger and step through, it changes the value. after the line of code executes, disabled does equal false, it just does not reflect on the page (the control stays greyed out)

Thanks for your input though

 
How about:

document.forms[0].elements[elemArray[6]].disabled = false;

Lee
 
Trollacious,

I tried your code, and it works the same as the original code that I had posted. I can see the value being changed when I step through the code in the debugger, but the change is not reflected on the control.

Thank you for you help though.
 

Is it a symptom of the debugger that the page is not updated immediately?

What happens if you run the code without the debugger?

Dan



The answers you get are only as good as the information you give!

 
BillyRay,

I get the same results whether I have the debugger attached or not. Actually, the only reason I ran it through the debugger was to try and figure out why it wasn't working.

I am still stumped
 
How about showing your output code? What's been posted here SHOULD work with the example you gave, so we're going to need to see real code to give you a real answer.

Lee
 
Here is the code exactly how it appears in the source of the page.

handleDrop is called from an asp:textbox onDrop property

the code WORKS, the changes are just not made to the page. Like I said before, If I enable them all by default and just change the disabled like to "=true" the corresponding checkbox becomes disabled when the event is fired, like it is supposed to. When i try to do it the opposite way (like this) the value changes, but nothing happens to the page.

Thanks for all your help guys.

Code:
function handleDrop() {
	var elem = window.event.srcElement;
	var passedData = window.event.dataTransfer.getData("Text");
	var errMsg = "";
	
	for (i=0; i < elemArray.length; i++) {
		elemChk = document.getElementById(elemArray[i]);
		if (elem != elemChk) {
			if (passedData == elemChk.value) {
				elemChk.innerText = '';
			}
		}
	}

	var elemChk;
	switch (elem.id) {
		case elemArray[1]:
			//Page Level 2
			//need to see if Level 1 is filled first
			blnMove = checkLevel(0,'Page Level 1 must be specified prior to specifying Page Level 2.');
			if (passedData == 'Measure') {
				blnMove = false;
				alert("Measure must not be in Page Level 2.");
			}
			break;
		case elemArray[3]:
			//Column Level 2
			//need to see if Level 1 is filled first
			blnMove = checkLevel(2,'Column Level 1 must be specified prior to specifying Column Level 2.');
			break;
		case elemArray[5]:
			//Row Level 2
			//need to see if Level 1 is filled first
			blnMove = checkLevel(4,'Row Level 1 must be specified prior to specifying Row Level 2.');	
			break;
		default:
			blnMove = true;
	}
	
	if (blnMove == true) {						
		window.event.dataTransfer.dropEffect = "copy";
		window.event.srcElement.innerText = passedData;
			
		// enable checkboxes
		switch (elem.id){
			case elemArray[2]:
				//document.forms[0][elemArray[6]].disabled = false;
				document.forms[0].elements[elemArray[6]].disabled = false;
				break;
			case elemArray[3]:
				document.forms[0][elemArray[7]].disabled = false;
				break;
			case elemArray[4]:
				document.forms[0][elemArray[8]].disabled = false;
				break;
			case elemArray[5]:
				document.forms[0][elemArray[9]].disabled = false;
				break;
		}//end switch
	} else {
		window.event.returnvalue=false;
	}
	


	
}
 
elemArray is filled in the startup script. if elemArray[2] is the textbox that had the value changed, then elemArray[2+4] holds the ClientID of the checkbox that corresponds to it. So it should only enable the checkbox that corresponds, which is why it is in the switch statement.
 
The code that I pasted sits in a custom control (ascx file) embedded in an ASP.NET page (aspx) it would be hard for me to post all of the code.

I just stepped through it in the debugger to show you the values. You will just have to take my word that the control on the page DOES NOT change to reflect the change in value shown in the debugger.

Debug Command Window (MS Script Debugger):
Code:
elem.id
"CL1_txtColumnL1"
elemArray[2]
"CL1_txtColumnL1"
elemArray[6]
"CL1_chkColumnLevel1"
document.forms[0].elements[elemArray[6]].disabled
true

[COLOR=red] this is after I step past the line which changes it [/color]
document.forms[0].elements[elemArray[6]].disabled
false
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top