checkbox won't uncheck (value still passed

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
yonkman
Forum Newbie
Posts: 2
Joined: Fri Dec 09, 2005 8:35 pm

checkbox won't uncheck (value still passed

Post by yonkman »

I am populating a checkbox array from a DB pull. Everyting works fine. The checkboxes that have been previously selected show up correctly.

However, if a user unchecks an item and posts the form, the array still shows that item as checked.

Anyone run into this before?

The code below creates the array. ROW holds the record set where the cols are the array items. ROW2 holds the array names from a lookup table.

Code: Select all

<?

$theCount = 0;
$theTrigger=0;

  while ( $Row2 = mysql_fetch_row( $demoResult2 ) ) 
  {
    if (round($theMidRow) == $theCount)
      {
      $theTrigger = 1;
      }
    if ($theTrigger == 1)
      {
      echo "</td><td>";
      $theTrigger = 2;
      }
  	
    echo "<input type='checkbox' name='amenities[]' value='".$Row2[2]."' ";
  	$theArrayIndex = $Row2[4];
  	if ($Row1[$theArrayIndex] == 1)
      	{
      	echo "checked='checked' ";
  			}
  
  			echo "> ".$Row2[1]."<br />";    
  
    ++$theCount;
  }
?>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Show your post code. The problem isn't with the selecting of the data it is with the form handling of the data.
yonkman
Forum Newbie
Posts: 2
Joined: Fri Dec 09, 2005 8:35 pm

post code

Post by yonkman »

Thank you!!!!

It was the form handling. The key value was duplicated in the DB I was pulling from. (garbage in, garbage out!!!!). Your response put me on the right debugging path.

Appreciate the insight.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Glad I could be of service.

PostCount++
Post Reply