Jump to content
xisto Community
adly3000

Make One Checkbox Checks All The Others thats a tutorials and not a question

Recommended Posts

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> </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;

Share this post


Link to post
Share on other sites
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. 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.