NYCPHP Meetup

NYPHP.org

[nycphp-talk] Javascript "select all" feature?

drydell at att.net drydell at att.net
Tue Apr 13 17:44:03 EDT 2004


an array construct should work on all browsers... this html works fine on IE and Netscape:


<html>
<head>
<title>States</title>
<script language="javascript">
<!--

function allstates(state, o) {

	var i;

	for (i = 0; i< o.length; i++) {
		o[i].checked = state;
	}

}

// -->
</script>
</head>
<form action="" method=post name=reg>

<table border=0 cellpadding=0 cellspacing=0><tr><td bgcolor=cccccc>
 <table border=0 cellpadding=3 cellspacing=1width=510>
  <tr bgcolor="#eeeeee">
   <td colspan="3">Select State: &nbsp; <a href="javascript:allstates(true, document.reg['stcd[]']);">select all</a> &nbsp; <a href="javascript:allstates(false, document.reg['stcd[]']);">select none</a></td>
  </tr>
  <tr>
   <td colspan="3" align=center bgcolor=ffffff>
    <table class=oo width=100%>       
<TR bgcolor=F3F3F1><td> <input name="stcd[]" type=checkbox value=AK checked> Alaska<br> </td>
<td> <input name="stcd[]" type=checkbox value=AL checked> Alabama<br> </td>
<td> <input name="stcd[]" type=checkbox value=AR checked> Arkansas<br> </td>
<td> <input name="stcd[]" type=checkbox value=AZ checked> Arizona<br> </td>
<td> <input name="stcd[]" type=checkbox value=CA checked> California<br> </td>
</TR>
<TR bgcolor=E6E7E1>
<td> <input name="stcd[]" type=checkbox value=CO checked> Colorado<br> </td>
<td> <input name="stcd[]" type=checkbox value=CT checked> Connecticut<br> </td>
<td> <input name="stcd[]" type=checkbox value=DC checked> Washington, DC<br> </td>
<td> <input name="stcd[]" type=checkbox value=DE checked> Delaware<br> </td>
<td> <input name="stcd[]" type=checkbox value=FL checked> Florida<br> </td>
</TR>
<TR bgcolor=F3F3F1>
<td> <input name="stcd[]" type=checkbox value=GA checked> Georgia<br> </td>
<td> <input name="stcd[]" type=checkbox value=HI checked> Hawaii<br> </td>
<td> <input name="stcd[]" type=checkbox value=IA checked> Iowa<br> </td>
<td> <input name="stcd[]" type=checkbox value=ID checked> Idaho<br> </td>
<td> <input name="stcd[]" type=checkbox value=IL checked> Illinois<br> </td>
</TR>
<TR bgcolor=E6E7E1>
<td> <input name="stcd[]" type=checkbox value=IN checked> Indiana<br> </td>
<td> <input name="stcd[]" type=checkbox value=KS checked> Kansas<br> </td>
<td> <input name="stcd[]" type=checkbox value=KY checked> Kentucky<br> </td>
<td> <input name="stcd[]" type=checkbox value=LA checked> Louisiana<br> </td>
<td> <input name="stcd[]" type=checkbox value=MA checked> Massachusetts<br> </td>
</TR>
<TR bgcolor=F3F3F1>
<td> <input name="stcd[]" type=checkbox value=MD checked> Maryland<br> </td>
<td> <input name="stcd[]" type=checkbox value=ME checked> Maine<br> </td>
<td> <input name="stcd[]" type=checkbox value=MI checked> Michigan<br> </td>
<td> <input name="stcd[]" type=checkbox value=MN checked> Minnesota<br> </td>
<td> <input name="stcd[]" type=checkbox value=MO checked> Missouri<br> </td>
</TR>
<TR bgcolor=E6E7E1>
<td> <input name="stcd[]" type=checkbox value=MS checked> Mississippi<br> </td>
<td> <input name="stcd[]" type=checkbox value=MT checked> Montana<br> </td>
<td> <input name="stcd[]" type=checkbox value=NC checked> N. Carolina<br> </td>
<td> <input name="stcd[]" type=checkbox value=ND checked> North Dakota<br> </td>
<td> <input name="stcd[]" type=checkbox value=NE checked> Nebraska<br> </td>
</TR>
<TR bgcolor=F3F3F1>
<td> <input name="stcd[]" type=checkbox value=NH checked> New Hampshire<br> </td>
<td> <input name="stcd[]" type=checkbox value=NJ checked> New Jersey<br> </td>
<td> <input name="stcd[]" type=checkbox value=NM checked> New Mexico<br> </td>
<td> <input name="stcd[]" type=checkbox value=NV checked> Nevada<br> </td>
<td> <input name="stcd[]" type=checkbox value=NY checked> New York<br> </td>
</TR>
<TR bgcolor=E6E7E1>
<td> <input name="stcd[]" type=checkbox value=OH checked> Ohio<br> </td>
<td> <input name="stcd[]" type=checkbox value=OK checked> Oklahoma<br> </td>
<td> <input name="stcd[]" type=checkbox value=OR checked> Oregon<br> </td>
<td> <input name="stcd[]" type=checkbox value=PA checked> Pennsylvania<br> </td>
<td> <input name="stcd[]" type=checkbox value=RI checked> Rhode Island<br> </td>
</TR>
<TR bgcolor=F3F3F1>
<td> <input name="stcd[]" type=checkbox value=SC checked> South Carolina<br> </td>
<td> <input name="stcd[]" type=checkbox value=SD checked> S. Dakota<br> </td>
<td> <input name="stcd[]" type=checkbox value=TN checked> Tennessee<br> </td>
<td> <input name="stcd[]" type=checkbox value=TX checked> Texas<br> </td>
<td> <input name="stcd[]" type=checkbox value=UT checked> Utah<br> </td>
</TR>
<TR bgcolor=E6E7E1>
<td> <input name="stcd[]" type=checkbox value=VA checked> Virginia<br> </td>
<td> <input name="stcd[]" type=checkbox value=VT checked> Vermont<br> </td>
<td> <input name="stcd[]" type=checkbox value=WA checked> Washington<br> </td>
<td> <input name="stcd[]" type=checkbox value=WI checked> Wisconsin<br> </td>
<td> <input name="stcd[]" type=checkbox value=WV checked> West Virginia<br> </td>
</TR>
<TR bgcolor=F3F3F1>
<td> <input name="stcd[]" type=checkbox value=WY checked> Wyoming<br> </td>
</TR>
    </table>
   </td>
  </tr>
</table></td></tr></table>

</form>

</body>
</html>






More information about the talk mailing list