PDA

View Full Version : Checkbox Values?


Intrigue25
06-08-2009, 01:14 PM
Hi,

I have a comment approval system for one of my clients and I am using a Checkbox to approve (ie: Yes ) the comments. The problem is that it Data Assist only allows you to give a value if the Checkbox is checked. How do i give it a value if the box is not checked or unchecked (ie: No) ?

Ray Borduin
06-08-2009, 03:56 PM
It should allow you to set the type of that field to "Checkbox Yes, No" which will insert the negative value when unchecked.

tom92909
09-09-2009, 06:57 AM
So a checkbox field (logical field) should always be numeric? Either a '1' or a '0' ?
Could you make a checkbox function correctly with updating records with that field being a CHAR(1)?


<?php
if ($row_WADAgallery['status'] == 'Y') {
?>
<td>Disable</td><td><input name="status" type="checkbox" value="N"></td>
<?php
} else {
?>
<td>Make Live!</td><td><input name="status" type="checkbox" value="Y"></td>
<?php
}
?>


The above isn't working correctly. The value already stored is getting changed to the opposite on every update save. This requires an additional separate update to change the original setting back to the correct state.

What am I doing wrong here?

Thanks!

Ray Borduin
09-09-2009, 09:04 AM
What is the field type you have set up in DataAssist.

Here is the problem, when you don't check a checkbox it doesn't return a value, when you do it returns the value specified.

Your technique to have a checkbox to disable or to enable depending on the start value just doesn't fit the paradigm very well. It would be much easier to have a single checkbox "check to enable or uncheck to disable".

Trying to get what you are doing to work would require more hand coding where the field is updated in the server code as well.

tom92909
09-09-2009, 09:26 AM
Ray,

As always thank you for your assistance. From your comments, I was able to successfully alter my technique by removing the 2nd checkbox entry and produce a functional solution.


<td>Make Live!</td><td><input <?php if (!(strcmp($row_WADARecordset1['status'],"Y"))) {echo "checked=\"checked\"";} ?> name="status" type="checkbox" value="Y"></td>



This was a case of over thinking the process. The above solution provides exactly what I needed!

Thanks again!