Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select All checkboxes twice in same form

Status
Not open for further replies.

weibs

Programmer
Dec 17, 2008
61
US
I hope I can explain this in a fashion that you all understand.

I have a form that shows multiple records from a database
Each row has two checkboxes, one is for Active (yes) and one is for Active (no). There are several rows with this same query.
ie:
City - Address - Yes - No - Submit

Right now I have it so that for each row, you need to select either yes or no and then hit submit for each one.

The client wants to be able to select all yes's or all no's at the same time and then a final submit button to append the information into the database.

Here is my code to date.
Code:
print <<OH; 
<form Action="openhouseAdmin.cgi" Method="post" name="frm">
<input type='hidden' name="action" value="activeconfirm2">
<input type='hidden' name="city" value="$input{'city'}">

<tr>
<td><FONT CLASS="BodyBold">&nbsp;$CityName</FONT></td>
<td><FONT CLASS="BodyBold">$StreetAddress</FONT></td>

OH

if ($Active eq "yes") {
$checkedyes = "checked";
$checkedno = "";
} else {
$checkedno = "checked";
$checkedyes = "";
}


print <<OH; 
	<td align ="Center"><input type="radio" name="Active" value="yes" $checkedyes></td><td align="center"> <input type="radio" name="Active" value="no" $checkedno></td>
	<td align=center><input name="MLSNumber" type="Hidden" value="$MLSNumber">
	<input type="Submit" Name="Submit" Value="Change"></form>
</td></tr>
OH
}

I have tried
Code:
<script> 
function CheckAll()
{
count = document.frm.elements.length;
    for (i=0; i < count; i++) 
	{
    if(document.frm.elements[i].checked == 1)
    	{document.frm.elements[i].checked = 0; }
    else {document.frm.elements[i].checked = 1;}
	}
}
function UncheckAll(){
count = document.frm.elements.length;
    for (i=0; i < count; i++) 
	{
    if(document.frm.elements[i].checked == 1)
    	{document.frm.elements[i].checked = 0; }
    else {document.frm.elements[i].checked = 1;}
	}
}
</script>

<form name="frm">
print <<OH; 
	<td align ="Center"><input type="radio" name="Active" value="yes" $checkedyes></td><td align="center"> <input type="radio" name="Active" value="no" $checkedno></td>
	<td align=center><input name="MLSNumber" type="Hidden" value="$MLSNumber">

<input name="btn" type="button" onclick="CheckAll()" value="Check All"> 
<input name="btn" type="button" onclick="UncheckAll()" value="Uncheck All"> 
</form>
OH

But that didn't work at all.

And of course once they are able to select all, it needs to update all records at the same time.

Any experts have some advice for me?

Thanks
 
Well no, I put this into the Perl forum as this is dealing with a Perl script.

My mistake on saying checkbox, I meant to say radio button.

Thanks for the link.
 
Ok, I've been able to get the select all to work, but now I can't figure out why I cannot update multiple records at the same time. Here is my code

Code:
	while( @emps = $sth->fetchrow) {
	$MLSNumber  = $emps[0];
	$SatHourFrom = $emps[1];
	$SatMinutesFrom = $emps[2];
        $SatHourTo = $emps[3];
       	$SatMinutesTo = $emps[4];
        $SunHourFrom = $emps[5];
        $SunMinutesFrom = $emps[6];
        $SunHourTo = $emps[7];
	$SunMinutesTo = $emps[8];
	$Headline1 = $emps[9];
	$Headline2 = $emps[10];
	$ListingPriceFrom = $emps[11];
	$IncludePlusSign = $emps[12];
	$ListingPriceTo = $emps[13];
	$Description1 = $emps[14];
	$Description2 = $emps[15];
	$StreetAddress = $emps[16];
	$CityName = $emps[17];
	$CityNameOther = $emps[18];
	$AgentName1 = $emps[19];
	$AgentName1Phone1 = $emps[20];
	$AgentName1Phone2 = $emps[21];
	$Agent1Days = $emps[22];
	$AgentName2 = $emps[23];
	$AgentName2Phone1 = $emps[24];
	$AgentName2Phone2 = $emps[25];
	$Agent2Days = $emps[26];
	$MarketedBy = $emps[27];
	$MarketedByDays = $emps[28];
	$bFeatureHome = $emps[29];
        $yahoo = $emps[30];
	$Active = $emps[31];
print <<OH; 
<form Action="openhouseAdmin.cgi" Method="post" name="frm1" id ="frm1">
<input type='hidden' name="action" value="activeconfirm2">
<input type='hidden' name="city" value="$input{'city'}">

<tr>
<td><FONT CLASS="BodyBold">&nbsp;$CityName</FONT></td>
<td><FONT CLASS="BodyBold">$StreetAddress</FONT></td>

OH

if ($Active eq "yes") {
$checkedyes = "checked";
$checkedno = "";
} else {
$checkedno = "checked";
$checkedyes = "";
}


print <<OH; 
	<td align ="Center"><input type="checkbox" name="Active" value="yes" $checkedyes><input name="MLSNumber" type="Hidden" value="$MLSNumber"></td>
</tr>
OH
}


print <<OH; 
</table> <br /><br />
<input type='checkbox' name='checkall' onclick='checkedAll(frm1);'> Check to make all Active, Uncheck to make all Non-Active<br />
<input type="Submit" Name="Submit" Value="Change"></form>
OH

		$sth->finish ();
		$dbh->disconnect();

and then

Code:
if ($input{'action'} eq 'activeconfirm2'){   

if ($input{Active} eq "") {
$input{Active} = "No";
}


        $sth = $dbh->prepare ("SELECT * FROM events where MLSNumber = '$input{MLSNumber}'");
	$sth->execute ();


          
 	$sth = "UPDATE events SET Active = '$input{Active}' WHERE MLSNumber = '$input{MLSNumber}'";
	$dbh->do( $sth ) or die( $dbh->errstr );   
 

       
&header; 
print <<OH;

		print "  
		<script language=\"JavaScript\">
		<!-- Begin
		var name = navigator.appName;
 		if (name == \"Microsoft Internet Explorer\")
		url=(\"[URL unfurl="true"]http://www.test.com/cgi-bin/tese.cgi?action=active2&city=$input{'city'}\");[/URL]
		else
		url=(\"[URL unfurl="true"]http://www.test.com/cgi-bin/test.cgi?action=active2&city=$input{'city'}\");[/URL]
		window.location=url;
		// End -->
		</script>
  		";
OH

But that only updates the last record.

Any hints on how to change all records at the same time?

Thanks in advance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top