3 Replies Latest reply on Jun 9, 2009 11:19 AM by Albert S.

    Check boxes not retaining their correct value

    921creative Level 1

      Hello, I have a perplexing issue going on. I have a simple, two checkbox form for updating two values in my login table. The row type is enum('y','n') so naturally a check box is my preferred way to set the value. Even though the value in the table is set to 'y', the check box in the form is never checked. I check it, click the submit button, and the update occurs in the table but the check box remains unchecked on the form. My code for the form is below. Any idea what I'm missing here?

       

      <form method="post" id="form4" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>">

                  <table cellpadding="4" cellspacing="0">

                    <tr><td><input  <?php if (!(strcmp(KT_escapeAttribute($row_rslogin['show_profile']),"y"))) {echo "checked";} ?> type="checkbox" name="show_profile" id="show_profile" value="y" /></td>

                      <td><label for="show_profile">Show my profile to other myJoy members.</label></td>

                    </tr>

                    <tr>

                    <td><input  <?php if (!(strcmp(KT_escapeAttribute($row_rslogin['get_mail']),"y"))) {echo "checked";} ?> type="checkbox" name="myjoymail_optout" id="myjoymail_optout" value="y" /></td>

                      <td><label for="myjoymail_optout">Send me myJoy email and notifications.</label></td>

       

                    </tr>

                    <tr>

                      <td></td><td><input type="submit" name="KT_Update3" id="KT_Update3" value="Save Prefs" /></td>

                    </tr>

                  </table>

                </form>

        • 1. Re: Check boxes not retaining their correct value
          Albert S. Level 3

          Hi,

           

          Well I took your code and changed it to:

           

          <?php if (!(strcmp("y","y"))) {echo "checked";} ?>

           

          Getting rid of the KT_escapeAttribute() and manually entered the y. It worked fine. And even with the KT_escapeAttribute() it will probably work fine. Have you doubled checked that the database is not storing a Captial Y or a 0 or 1? Your using varchar correct, not char?

          • 2. Re: Check boxes not retaining their correct value
            921creative Level 1

            Thanks Albert for the suggestion. It still doesn't work. The column type was ENUM, and it stores either a 'y' or an 'n'. I did as you suggested with the code and now instead of the boxes being unchecked all the time, they are checked all the time, no matter what the value in the database.

             

            I even changed the column type to VARCHAR with a length of 1, which didn't work. Any other options for me, or do I need to switch to the dreaded pop-up menu for my preferences?

            • 3. Re: Check boxes not retaining their correct value
              Albert S. Level 3

              Hi,

               

              I only edited your code to make sure it was working correctly, not for you to actually use that code as yes it will make the box checked all the time.

              So since you know the code is working fine you need to find the problem else where. Maybe echo the values before the checkbox and make sure the values are correct. If it is i'm not really sure what it could be.