simon551
IS-IT--Management
- May 4, 2005
- 249
Hi, I have a form that lists many records that the user can click and then update records in a database.
I would like to create a 'check all' button kind of like the one below. My problem, though is that the script seems to require the fields to be named a certain way. My programming code requires the fields to be just like this though:
So my question is, in looking at the script below, do you see a way to modify it so that I could use it with an id or class attribute of the checkbox rather than the name or value?
Thanks in advance!
-s
I would like to create a 'check all' button kind of like the one below. My problem, though is that the script seems to require the fields to be named a certain way. My programming code requires the fields to be just like this though:
Code:
<input type="checkbox" name="checked[<?php echo $row_rs1['activityID']; ?>]" value="<?php echo $row_rs1['contractID']; ?>" />
So my question is, in looking at the script below, do you see a way to modify it so that I could use it with an id or class attribute of the checkbox rather than the name or value?
Thanks in advance!
-s
Code:
<!-- TWO STEPS TO INSTALL CHECK ALL:
1. Copy the coding into the HEAD of your HTML document
2. Add the last code into the BODY of your HTML document -->
<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Modified By: Steve Robison, Jr. (stevejr@ce.net) -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! [URL unfurl="true"]http://javascript.internet.com[/URL] -->
<!-- Begin
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;}
checkflag = "true";
return "Uncheck All"; }
else {
for (i = 0; i < field.length; i++) {
field[i].checked = false; }
checkflag = "false";
return "Check All"; }
}
// End -->
</script>
</HEAD>
<!-- STEP TWO: Copy this code into the BODY of your HTML document -->
<BODY>
<center>
<form name=myform action="" method=post>
<table>
<tr><td>
<b>Your Favorite Scripts & Languages</b><br>
<input type=checkbox name=list value="1">Java<br>
<input type=checkbox name=list value="2">JavaScript<br>
<input type=checkbox name=list value="3">ASP<br>
<input type=checkbox name=list value="4">HTML<br>
<input type=checkbox name=list value="5">SQL<br>
<br>
<input type=button value="Check All" onClick="this.value=check(this.form.list)">
</td></tr>
</table>
</form>
</center>
<p><center>
<font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
by <a href="[URL unfurl="true"]http://javascriptsource.com">The[/URL] JavaScript Source</a></font>
</center><p>
<!-- Script Size: 1.47 KB -->