Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

Make One Checkbox Checks All The Others


3 replies to this topic

#1 adly3000

    Member [Level 1]

  • Kontributors
  • PipPipPipPip
  • 58 posts

Posted 07 February 2006 - 11:12 AM

i learned the last night a new trick so i write it to you, may help you later:
1- that makes the upper checkbox check or uncheck all the other check boxes.
2- on check or uncheck the bg of that checkbox will change.
you may say it's easy but i used array name in the checkboxes whcih makes it difficult really ver difficult.(mmmm.. so ask why i choosed the hard way instead of naming my checkboxes box1,box2,...etc., cuz i use php code and i need to make an array for later use.)
and here's the code:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
function check()
{
	var length = document.form1.elements.length;
	if (document.form1.checkall.checked==1)
	{
		for (i=length-1; i>0; i--)
		{
			var e = document.form1.elements[i];
			if (e.type=='checkbox' && e.name.indexOf("dmsg") != -1)
			{
				e.checked=1;
				var msgno = 'msg'+i;
				changebg(e, msgno);
			}
		}
	}
	else
	{
		for (i=length-1; i>0; i--)
		{
			var e = document.form1.elements[i];
			if (e.type=='checkbox' && e.name.indexOf("dmsg") != -1)
			{
				e.checked=0;
				var msgno = 'msg'+i;
				changebg(e, msgno);
			}
		}
	}
}
function changebg(row, msgno)
{
	var checkrow = row;
	if (checkrow.checked == 1)
	{
		document.getElementById(msgno).bgColor="#66CCFF";
	}
	else
	{
		document.getElementById(msgno).bgColor="#FFFFFF";
	}
}
</script>
</head>

<body>
<form name="form1" method="post" action="">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr> 
	  <td align="center"><input type="checkbox" name="checkall" value="checkbox" onClick="check();"></td>
	  <td>&nbsp;</td>
	</tr>
	<?
	for ($x=10; $x>0; $x--)
	{
	?>
	<tr id="msg<? echo $x; ?>">
	  <td align="right" style="bgcolor: #ff0000"><input type="checkbox" name="dmsg[]" value="<? echo $x; ?>" onClick="changebg(this, 'msg<? echo $x; ?>');"></td>
	  <td>box <? echo "$x"; ?></td>
	</tr>
	<?
	}
	?>
  </table>
</form>
</body>
</html>
i hope that may help you in future.
Ahmed;

#2 snlildude87

    Moderator

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 2,325 posts
  • Location:Mawson, Antarctica

Posted 16 February 2006 - 02:30 AM

I've been wondering how this technique that I've seen in many forms is implemented, but I never bothered to research. Now I know!

Thanks for posting.

#3 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 10 January 2010 - 09:32 PM

what happens if there is only one checkbox, then the .Length function results in an error



#4 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 20 April 2010 - 04:45 PM

how to convert checkbox array to String array?Make One Checkbox Checks All The Others

Hi,

 Iam getting a problem converting from checkbox arrayto string array.

Give me suggestion.

Thanks in advance. 






Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users