Solved

Javascript to handle DDL and checkbox

Posted on 2014-04-08
5
425 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
The error message occurred when I enabled IE debugging and clicked the DDL.

Appreciated!!
0
 

Author Closing Comment

by:jssong2000
Comment Utility
It worked. Thank you!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

772 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

15 Experts available now in Live!

Get 1:1 Help Now