Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

Check/uncheck checkboxes from javascript

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dilip - 12 Jul 2007 20:11 GMT
I am writing a WebControl that uses the status of a master check box
to determine if other dependent check boxes need to be checked/
unchecked.  What is the best way to do it?  I am not much of a web
programmer so apologies for the basic question.

Currently the way I see it being done is to generate individual
'javascript:' calls to a function on the master checkbox's onclick
handler, passing in the ID of the master and each dependent control
and flipping the latter based on the former.  Is this the way to go?

IOW:

<....checkbox control HTML......
onclick="javascript:enableCB("master_ctrl","cb_1");enableCB("master_ctrl","cb_2") /

function enableCB(master, slave)
{
   document.getElementById(slave).disabled = !
document.getElementById(master).checked;
   document.getElementById(slave).parentNode.disabled = false; // I
don't even know why this is done :-(
}
tomisarobot@gmail.com - 12 Jul 2007 20:59 GMT
its one way to go.

a much simpler way is to set your checkboxes to AutoPostBack=true and
then handle it in the aspx.cs code behind.

you javascript gets a lot more complicated if you have your checkboxes
in a parent container that renames their ClientID, such as MasterPages
and any of the databound (datagrid/view/list/etc) type controls.

unless you are horribly concerned with bandwidth id just post back and
not worry about javascript.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.