mercredi 24 février 2016

Why post value for checkbox is 'on'?

The standard says: Value attribute is optional except when the type attribute has the value "radio" or "checkbox".

But when I have <input type='checkbox'> with no value the browser sends 'on' value instead.

Is there any document or standard what value the browser should encode into into POST data when the 'value' attribute for checkbox is undefined?




PHP export excel with checkbox

I want to export an excel file with checkbox like the picture below but i don't know how to do it. Please help me!

Thanks so much! enter image description here




update several records at the same time

I have a form with dynamic table (PHP/MYSQL) where some records are been show with checbox and i want to update this records with one button click by selecting or deselecting the checkboxes. My checkbox checked value is set to 2, blank will be 1 (default on mysql table).

Any sugestion or example for this updates?

My table

ID | CHKBOX1 | CHKBOX2 | CHKBOX3 | CHKBOX4
1  |   x     |    X    |         |    X
2  |   x     |         |    X    |    X
3  |         |    X    |         |    X
4  |   x     |         |         |    X




jQuery if checkbox "A" is checked from list 1, check "A" on list 2

I have a main list of checkboxes:

<div id="main_list">
<input name="main_list[]" class="main-checkbox" value="Austin" checked="" type="checkbox">
<input name="main_list[]" class="main-checkbox" value="San Antonio" checked="" type="checkbox">
<input name="main_list[]" class="main-checkbox" value="El Paso" checked="" type="checkbox">
</div>    

I would like to match the two lists, for example if "Austin" is checked on main list, check on single list.

<div id="single_list">
<input name="checkbox_list[]" class="list-checkbox" value="Austin" type="checkbox">
<input name="checkbox_list[]" class="list-checkbox" value="Houston" type="checkbox">
<input name="checkbox_list[]" class="list-checkbox" value="Dallas" type="checkbox">
</div>

How can I accomplish it? Thanks in advance.




CakePHP 3 - Form Select Option Group - Multiple Checkboxes

First, I've successfully implemented a Multiple Select box with option groups based on providing an providing a group of options structured like this:

$options = [
   'Group 1' => [
      'Value 1' => 'Label 1',
      'Value 2' => 'Label 2'
   ],
   'Group 2' => [
      'Value 3' => 'Label 3'
   ]
];
echo $this->Form->select('field', $options);

This is straight from the Cookbook at: http://ift.tt/1OhBL7S

It works great, and makes a select box exactly as it should. My issue is that I would like to change the display to be multiple checkboxes. In order to do that, I've switched the code to:

echo $this->Form->input('field', [
        'multiple' => 'checkbox',
        'options' => $options
    ]);

When I do this, the display ends up being a single checkbox, with all the options listed out next to it.

In searching stackoverflow, I found the following: How to create multiple checkboxes grouped by fieldsets in Cakephp 3

Most seem to indicate that the functionality is not included in Cake, and that you need to build it on your own. There is one comment on the initial question that references the cookbook and that it specifically states:

If you would like to generate a select with optgroups, just pass data in hierarchical format. This works on multiple checkboxes and radio buttons too, but instead of optgroups wraps elements in fieldsets:

No one seems to address the comment on that question. My question is really simple. Does CakePHP 3 allow for multiple checkboxes created as outlined in the documentation, or is the documentation incorrect and this functionality isn't included in the core? If the answer is that the functionality is included in the core, what's the trick to getting it to work?

Thanks!




How to target only the ID in the div with addClass on a checkbox

I am trying to only target the div associated with the checkbox. Right now the script I am using only changes the class of the first div with the ID of taskList instead of the one where the checkbox is located.

$('input:checkbox').change(function(){
if($(this).is(":checked")) {
    $('#taskList').addClass("complete");
} else {
    $('#taskList').removeClass("complete");
}
});




How to check state of a checkbox and update database accordingly

I am making a check to see if the user account is freeze, this is in my database, $r is where I am getting the user data (name, freeze account, etc).

So if the freeze account is set to be 0 then I am showing a unchecked box otherwise a checked box. It works fine, however my question is how could I save it if I checked the box to say that the user account is freeze.

I know how to write the query if they check the box to say that the user account is freeze, just calling this function :

function updatefreezeaccount(){
mysql_query("UPDATE `users` SET `freeze_account` = 1 WHERE `user_id` = '$user_id'");
}

This is my code so far :

<?php
      if ($r['freeze_account'] == 0) {
          echo '<div class="example">
          <input type="checkbox" unchecked data-toggle="toggle">
          </div>';
      } 
      else {
          echo '<div class="example">
          <input type="checkbox" checked data-toggle="toggle">
          </div>';
      }
?>

However I don't know how to make the check to see if the user has checked the box or not, any suggestion would be appreciated, thanks