1

I have a input checkbox field, where its name generate dynamically using JavaScript.

<input type="checkbox" name="options_'.$j.'"  class="check">

Now, I want to check whether any checkbox is checked or not in if condition. I have written the following code. But it is not working. Please help me to correct the code.

for($i = 0; $i<=1; $i++)
    {
        if(!isset($_POST['options_ '.$i]))
        {
            echo $error;
        }
        $i++;
    }

Is this is the correct format?

3
  • 3
    Remove second $i++; Commented Sep 13, 2017 at 6:40
  • for($i = 0; $i<=count($_POST); $i++) { if(!isset($_POST['options_ '.$i])) { echo $error; } } Commented Sep 13, 2017 at 6:41
  • 1
    why don't you go for <input type="checkbox" name="options['.$j.']" class="check"> in your HTML, now you can use count ($_POST['options']) directly instead of this much code Commented Sep 13, 2017 at 7:16

1 Answer 1

1

the $i++; is not neccesary the one in the for will do it for you

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.