Solved

Javascript to handle DDL and checkbox

Posted on 2014-04-08
5
441 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…

717 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