-1

I've got a set of checkboxes but one shuld be always checked, I want that this checkbox is also hidden from my page, I need this beacause I have the DB that can be read only if this attribute is checked.. Please I need answers where you teach me how to hide the checkbox and NOT where you say that I can change the comand on SQL

$sqlPers= "SELECT * FROM personalizzazione";
$countPers = 0;
foreach ($dbh->query($sqlPers) as $rowPers){
    $selez = '';
        if($rowPers['Condimento'] == 'Base')
            $selez = " checked = 'checked' ";
    echo "<div class='checkbox'><label class='bianco'><input type='checkbox'" . 
          $selez . "name='".$rowPizza["idPizze"]."_".$rowPers["idPersonalizzazione"].
          "' id='".$rowPizza["idPizze"]."_".$rowPers["idPersonalizzazione"]."'>".
          $rowPers['Condimento']."&nbsp;(&euro; &nbsp;".$rowPers['Prezzo'].")</label></div>";
          $countPers++;
}

I tried to add type = 'hidden' in the variable $selez but nothing

Otherwise can someone say me how to disable it or hide it throught ccs? I've tried searching on internet and there weren't full solutions for my question

9
  • It can't be type hidden and checkbox. You can either disable it or use css to hide it. Commented Jun 19, 2016 at 0:42
  • @JeffPuckettII Can you write me how to hide it in css or disable it? Commented Jun 19, 2016 at 0:44
  • I'm on my phone right now, but I've bookmarked and will check back later if no one else jumps on it Commented Jun 19, 2016 at 0:46
  • display :none or visibility:hidden Commented Jun 19, 2016 at 0:46
  • 4
    Possible duplicate of How can I hide a checkbox in html? Commented Jun 19, 2016 at 0:53

3 Answers 3

3

There are two things you can do:

Method 1 - Hide it using CSS:

<input type='checkbox' style='display:none;'>


Method 2 - Use a hidden type instead of checkbox:

Another option would not have a checkbox, but rather have a separate hidden input tag.

<input type='hidden' name='pizza' value='value'>
Sign up to request clarification or add additional context in comments.

7 Comments

This is the best answer and I was going to write the same. You can then change the display: none; with JS.
This checkbox is generated form the DB, your answer makes only the checkbox hide, I need to hide also the description
@Biondo Easy! Just apply the style='display:none;' to the <div class="checkbox">...</div> rather than the <input>
@StephenCioffi you are saying that I should move the variable $selez in div and the game is done? 😀 I'll try it tomorrow because It's 3:30 am in Italy 😅 I need to sleep
@Biondo No, leave $selez where it is. That code is the part that is actually checking off the box. To hide the checkbox and description, simply change <div class='checkbox'> to <div class='checkbox' style='display:none;'>
|
-1

You can hide it with style="display:none;" But since it is hidden, does it have to be a checkbox?
A regular hidden input would do the job, too.

Comments

-1

Look at the HTML that gets sent to the browser: You have already set type='checkbox' in your string, so having an additional type='hidden' may not give you what you want. You end up with <input type='checkbox' type='hidden'...

Your error was tough to see because you're writing your code in a way that is really difficult to debug. It's better practice to do all the logic up front. You're better off building all the attributes in code first. For example:

//run test to make $hide true for the loop where you want to hide the checkbox
$type = 'checkbox';
$style = $hide? "display:none" : "";
$name = $id = "$rowPizza[idPizze]_$rowPers[idPersonalizzazione]";
...

//then later when you can build your html

$html = "<div class='checkbox'><label class='bianco'><input type='$type' name='$name' id='$id' style='$style'>";

//Finally once you've built the whole html you can echo it
echo $html;

Note that we set display:none style when the $hide variable is true. Otherwise, the style will just be an empty string and the checkbox will be shown

5 Comments

You are absolutely right but the checkbox is always on the display, I want that this checkbox disappears from my display
Please leave feedback when you downvote so people trying to help can figure out how to improve their answers.
I can't, I'm new and I have to get points on this forum for leave a feedback
@Biondo, I don't think Patrick was talking to you. this looks like a good answer and the only reason I can see why it might get downvoted is because technically there's a syntax error missing a semicolon ; at the end of this line $html = "...
There, I added the semi-colon. Looks good to me now.

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.