Solved

Javascript to handle DDL and checkbox

Posted on 2014-04-08
5
432 Views
Last Modified: 2014-04-09
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
Comment
Question by:jssong2000
  • 3
5 Comments
 
LVL 8

Expert Comment

by:deepu chandran
ID: 39988160
Hi,

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

Thanks
Deepu
0
 
LVL 9

Accepted Solution

by:
Sar1973 earned 500 total points
ID: 39988328
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
 

Author Comment

by:jssong2000
ID: 39989000
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
 

Author Comment

by:jssong2000
ID: 39989003
The error message occurred when I enabled IE debugging and clicked the DDL.

Appreciated!!
0
 

Author Closing Comment

by:jssong2000
ID: 39989748
It worked. Thank you!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question