Topic: getFormValues Checkbox issue - all checkboxes are always checked

When using getFormValues, all my checkboxes are passed to my Xajax function as if they were checked.   I am completely mystified on why it is doing this because all the examples that I see online seem to have no problems.   Can anyone see what my issue is?  I'll paste the script which has the issue.  No matter what I uncheck on the form.   The checkboxes 'kw_label', 'kw_sub1', 'kw_sub2', and 'kw_sub3' are passed as Checked.   I have no problems with the radio buttons. 
Help!

<?PHP
$userid = $_COOKIE['userid'];
if ( $userid == '')
{header( "Location: index.php");}

require_once("./xajax/xajax_core/xajax.inc.php");
function process_form_data($form_data)
{
include( "DBinfo.inc");
$cxn = mysqli_connect( $host, $dbuser, $dbpassword, $dbname );

//session_start();
$userid = $_COOKIE['userid'];

$kw_label = isset($form_data['kw_label']) ? ("X") : ("");
$kw_sub1 = isset($form_data['kw_sub1']) ? ("X") : ("");
$kw_sub2 = isset($form_data['kw_sub2']) ? ("X") : ("");
$kw_sub3 = isset($form_data['kw_sub3']) ? ("X") : ("");

$sql = "UPDATE usermenu SET inline_yn=\"".$form_data['inline_yn']."\", auto_kw_yn=\"".$form_data['auto_kw_yn']."\",

kw_label=\"".$kw_label."\", kw_sub1=\"".$kw_sub1."\", kw_sub2=\"".$kw_sub2."\", kw_sub3=\"".$kw_sub3."\" WHERE userid = \"".$userid."\"";

$result = mysqli_query($cxn, $sql);

$response = new xajaxResponse();
$response->call("UpdateComplete",$result);
return $response;
}

$xajax = new xajax();

//$xajax->setFlag("debug", true);
$xajax->registerFunction("process_form_data");

$xajax->processRequest();

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<TITLE>My Content</TITLE>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<?php $xajax->printJavascript("./xajax/") ?>
<SCRIPT type="text/javascript">

function UpdateComplete(result)
{
if ( result == '1')
{alert('Your settings have been saved.');}
}

</script>

</head>
<body>

<?PHP

/*Define Variables*/

$user  = $_COOKIE['userid'];


include( "DBinfo.inc");           

$cxn = mysqli_connect( $host, $dbuser, $dbpassword, $dbname );

$sql = "SELECT inline_yn, auto_kw_yn, kw_label, kw_sub1, kw_sub2, kw_sub3 FROM usermenu wHERE userid = '$user'";
$result = mysqli_query($cxn, $sql);
$userdata = mysqli_fetch_array($result);


echo "<form id='MyContentForm' >";

echo "<input type='hidden' id='userid' name='userid' value='$user' ></input>";

echo "<table>";

if ( $userdata['inline_yn'] == 'Y')
   {
   echo "<tr><td><input type='radio' id='inlineN' name='inline_yn' value='N' >1<br></input></td>
         <td><input type='radio' id='inlineY' name='inline_yn' value='Y' checked>2<br></input></td></tr>";

   }
else
   {   
   echo "<tr><td><input type='radio' id='inlineN' name='inline_yn' value='N' checked>1<br></input></td>
         <td><input type='radio' id='inlineY' name='inline_yn' value='Y' >2<br></input></td></tr>";

   }

if ( $userdata['auto_kw_yn'] == 'N')
   {
   echo "<tr><td><input type='radio' id='autoN' name='auto_kw_yn' value='Y' >1<br></input></td>
             <td><input type='radio' id='autoY' name='auto_kw_yn' value='N' checked>2 <br></input></td></tr>";

   }
else
   {
   echo "<tr><td><input type='radio' id='autoN' name='auto_kw_yn' value='Y' checked >1<br></input></td>
             <td><input type='radio' id='autoY' name='auto_kw_yn' value='N' >2<br></input></td></tr>";

   }

echo "</table>";


if ( $userdata['kw_label'] == 'X')
   { echo "<input type='checkbox' id='kw_label' name='kw_label[]' value='1' checked >Label</input>";}
else
   { echo "<input type='checkbox' id='kw_label' name='kw_label[]' value='1' >Label</input>";}

if ( $userdata['kw_sub1'] == 'X')
   { echo "<input type='checkbox' id='kw_sub1' name='kw_sub1[]' value='1'  checked>Sub 1</input>";}
else
   { echo "<input type='checkbox' id='kw_sub1' name='kw_sub1[]' value='1' >Sub 1</input>";}

if ( $userdata['kw_sub2'] == 'X')
   { echo "<input type='checkbox' id='kw_sub2' name='kw_sub2[]' value='1'  checked>Sub 2</input>";}
else
   { echo "<input type='checkbox' id='kw_sub2' name='kw_sub2[]' value='1' >Sub 2</input>";}

if ( $userdata['kw_sub3'] == 'X')
   { echo "<input type='checkbox' id='kw_sub3' name='kw_sub3[]' value='1'  checked>Sub 3</input>";}
else
   { echo "<input type='checkbox' id='kw_sub3' name='kw_sub3[]' value='1' >Sub 3</input>";}


echo "<input type='button' value='Save' onclick=\"xajax.call('process_form_data', {parameters:[xajax.getFormValues('MyContentForm')],

mode:'synchronous'});\">


</form>";
?>

</body>
</html>

Re: getFormValues Checkbox issue - all checkboxes are always checked

Sorry, I found my problem.  I had changed the XAJAX CORE .js to have getFormValues pass disabled objects also.  If you do this, then the Checkboxes always are passed as checked.

Re: getFormValues Checkbox issue - all checkboxes are always checked

This is interesting.  I'll see if there is a way to keep this from happening.

// Joe

xajax Developer
Connect to me on LinkedIn:
http://www.linkedin.com/in/calledtoconstruct

Re: getFormValues Checkbox issue - all checkboxes are always checked

i have same isue .

here is example

<input name="checkit" id="checkit" type="checkbox" value="1" onChange="xajax_dbsay(xajax.$('checkit').value);" />

function dbsay($str)
{
        $objResponse = new xajaxResponse();
        $objResponse->append("box","innerHTML",$str);
        return $objResponse;
}

checked or not allways sending 1 value.

i'm not lucky as rspark08 i cant solve it.

Re: getFormValues Checkbox issue - all checkboxes are always checked

i found  something, if i send all form it's working fine.

when i try to get one part of the form

xajax.$('checkit').value

checkbox value returns  true. i think same problem sending form's checkbox (rspark08) and need some fix

can anybody help ?