Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4250224
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:30:02+00:00 2026-05-21T04:30:02+00:00

I am thinking this is doable? Maybe? Here is my checkbox input: <input type=’checkbox’

  • 0

I am thinking this is doable? Maybe?

Here is my checkbox input:

<input  type='checkbox' name='cb_name' id='cb_name' checked='checked' />

I Need an if else statement that checks only if the Checkbox was changed.

I have other input fields on the form. And if the checkbox wasn’t touched or checked, then SAVE the form without doing the checkbox condition.

If checkbox was checked before and now is != ‘checked’ then do this.

&&

If checkbox was != ‘checked’ before and now is = ‘checked’ then do this.

&&

and then finally, if checkbox was left alone (NO VALUE WAS CHANGED) then do the other form stuff without running the checkbox condition statement??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T04:30:02+00:00Added an answer on May 21, 2026 at 4:30 am

    To do this, you must have some reason to decide when displaying the form if the check box is checked or not. This is your initial state.

    Because we don’t know how you are deciding this, why not add a hidden field with the value like so, setting the value to match if the checkbox is checked (ie checked/unchecked):

    <input type="hidden" name="cb_hidden" value="<?php print $checkedOrNot; ?>" />
    

    We don’t know your condition for why the checkbox is checked, however this should solve the simple idea abstractly

    <?php
    $checkedOrNot = '';
    if(/* the condition that decides if things are checked */) {
        $checkedOrNot = 'checked';
    }
    ?><input type="checkbox" name="cb_name" checked="<?php print $checkedOrNot; ?>" />
    <input type="hidden" name="cb_hidden" value="<?php print $checkedOrNot; ?>" />
    

    Then when you get your post data

    <?php
    if(isset($_POST['cb_name']) && $_POST['cb_hidden'] != 'checked') {
        //if the checkbox was changed to checked
    } elseif(!isset($_POST['cb_name']) && $_POST['cb_hidden'] == 'checked') {
        //if the checkbox was changed to unchecked
    }
    

    This is a solution without needing previous state

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Maybe I'm just thinking about this too hard, but I'm having a problem figuring
What are the different types of encapsulation? Am I right in thinking this basically
While thinking about this question and conversing with the participants, the idea came up
I've been thinking about this object oriented design question for a while now and
I've been thinking about this problem for a while and have yet to come
A discussion about Singletons in PHP has me thinking about this issue more and
Can I specify interfaces when I declare a member? After thinking about this question
Reading this blog post about HttpOnly cookies made me start thinking, is it possible
I'm thinking about how to do this, but I have several different shapes of
This is something that comes up so often I almost stopped thinking about it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.