• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 458
  • Last Modified:

Javascript to handle DDL and checkbox

Hi Expert,

I dynamically created one dropdownlist and two checkboxes in code behind.
but I want to use javascript to handle dropdownlist and checkboxes. when user chose from dropdownlist(selectedindex>0), javascript should uncheck and disable two check boxes; when one checkbox is checked, another check box should be unchecked and disabled, and dropdownlist should be selectedindex=0 and disabled.

There is some code in javascript could handle onecheckbox is checked and another checkox to be unchecked and disabled.

Please check attachment for code behind and javascript.

Very appreciated for your help!!
javascriptissue.txt
0
jssong2000
Asked:
jssong2000
  • 3
1 Solution
 
deepu chandranCommented:
Hi,

The javascript code looks complicated, I recommand you ro use JQuery instead of plane javascript

Thanks
Deepu
0
 
Sar1973Commented:
Add this onchange="myFunction()" event to both dropdown and check boxes:

function myFunction() {
	if(document.getElementById("myComboID").selectedIndex>0) {
	document.getElementById("myCheck1").checked=false;
	document.getElementById("myCheck1").disabled=true;
	document.getElementById("myCheck2").checked=false;
	document.getElementById("myCheck2").disabled=true;
	} else {
	document.getElementById("myCheck1").checked=true;
	document.getElementById("myCheck1").disabled=false;
	document.getElementById("myCheck2").checked=true;
	document.getElementById("myCheck2").disabled=false;
	}
	if(document.getElementById("myCheck1").checked) {
	document.getElementById("myComboID").selectedIndex=0;
	document.getElementById("myComboID").disabled=true;
	document.getElementById("myCheck2").checked=false;
	document.getElementById("myCheck2").disabled=true;
	}
	if(document.getElementById("myCheck2").checked) {
	document.getElementById("myComboID").selectedIndex=0;
	document.getElementById("myComboID").disabled=true;
	document.getElementById("myCheck1").checked=false;
	document.getElementById("myCheck1").disabled=true;
	}
}

Open in new window

Please notice that the logical conditions you have set may generate conflicts.
0
 
jssong2000Author Commented:
I added the following line to my dynamically created DDL. I try to add "onchange" event.

ddlDqFormTypes.Attributes.Add("onchange", "SingleSelectDDL('ddl',this);");

But the webpage was frozen. I see an error message:

'Go to Definition' failed either because the caret is already at the definition or because an explicit definition could not be found.
0
 
jssong2000Author Commented:
The error message occurred when I enabled IE debugging and clicked the DDL.

Appreciated!!
0
 
jssong2000Author Commented:
It worked. Thank you!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now