472,133 Members | 1,172 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,133 software developers and data experts.

checkboxes and javascripts in .net

i have a checkbox
[HTML]<input name="AllCompanies" id="Checkbox3" type="checkbox" onclick=chkall1() checked/>All Companies
[/HTML]On this onclick I have called the below javascript

Expand|Select|Wrap|Line Numbers
  1. function chkall1()
  2. {
  3. if(document.getElementById("Checkbox3").checked=true)
  4. {
  5. document.getElementById("Checkbox3").checked=false;
  6. for (var n=0; n < document.forms[3].length; n++)
  7. {
  8. if (document.forms[3].elements[n].type=='checkbox' && document.forms[3].elements[n].id!='Checkbox3')
  9. {
  10. document.forms[3].elements[n].checked=false;
  11. document.forms[3].elements[n].disabled=false;
  12. }
  13. }
  14. }
  15. else
  16. {
  17. document.getElementById("Checkbox4").checked=true;
  18. for (var n=0; n < document.forms[3].length; n++)
  19. {
  20. if (document.forms[3].elements[n].type=='checkbox' && document.forms[3].elements[n].id!='Checkbox4')
  21. {
  22. document.forms[3].elements[n].checked=true;
  23. document.forms[3].elements[n].disabled=true;
  24. }
  25. }
  26. }
  27. return false;
  28. }
When I execute this the output is
The all companies check box is checked in the output.

Now the thing I need is when I click on the checked all companies checkbox it must be unchecked and all the checkboxes below this checkbox must be enabled and checked.for this I have written the javascript. When I click it for second time I need the checkbox to be checked for which I have written the else part in javascript and it doesnot work.it works for only one click
Aug 17 '07 #1
2 1238
kestrel
1,071 Expert 1GB
Hey rathiagu, Welcome To The Scripts!
Im going to move this question to the Javascript forum. Have a nice day!

--
Kestrel
Aug 17 '07 #2
acoder
16,027 Expert Mod 8TB
Please use CODE tags when posting code.

On line 3, you're setting instead of checking the checked property, i.e. you need double equals (==) instead of single (=).
Aug 17 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Kerberos | last post: by
2 posts views Thread by LC's No-Spam Newsreading account | last post: by
3 posts views Thread by claudel | last post: by
4 posts views Thread by David Virgil Hobbs | last post: by
4 posts views Thread by swayze | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.