Solved

Javascript to handle DDL and checkbox

Posted on 2014-04-08
5
427 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now