samedi 26 août 2017

group of checkboxes with that work correctly

I searched a lot but couldn't find a correct answer that I'm looking for. I want to have a group of checkboxes in a form that if they are checked, they work correct and show it in a div tag.

export class MyComponent {
options = [
{name:'OptionA', value:'1', checked:true},
{name:'OptionB', value:'2', checked:false},
{name:'OptionC', value:'3', checked:true}
]
get selectedOptions() { // right now: ['1','3']
return this.options
          .filter(opt => opt.checked)
          .map(opt => opt.value)
  }
}

and html:

<div class="form-group">
<label for="options">Options:</label>
<div *ngFor="let option of options">
    <label>
        <input type="checkbox"
               name="options"
               value=""
               [(ngModel)]="option.checked"/>
        
    </label>
</div>

but I'm sure it's not correct because the checked property is given by myself and if user changes it doesn't work. Could you please help me to write a simple code for checkbox? Thank you very much.




vendredi 25 août 2017

PHP keep checkbox checked after submitting POST form

How can I keep checkbox checked after submitting a form? I tried to this method:

<input type = "checkbox" name="math[]" value="Addition" <?php if(isset($_POST['math'])) echo "checked='checked'";?>/>Addition<br>

but all of my checkbox will keep checked even if I only select one, here is my code:

<form id="calc" action="calculator.php" method="POST" >
<b>Enter First No:  <br>    
<input type = "text" name="num1" value="<?php if(isset($_POST['num1'])){echo $num1;} ?>" required="required"/><br>
Enter Second No: <br>
<input type = "text" name="num2" value="<?php if(isset($_POST['num2'])){echo $num2;} ?>" required="required"/><br>
<b>Select Operation: <br>
<input type = "checkbox" name="math[]" value="Addition" <?php if(isset($_POST['math'])) echo "checked='checked'";?>/>Addition<br>
<input type = "checkbox" name="math[]" value="Subtraction" <?php if(isset($_POST['math'])) echo "checked='checked'";?>/>Subtraction<br>
<input type ="submit" value="compute" name="btnsubmit"> <br>

Thanks!




Checkbox.Ischecked always gives false

My checkbox is always returning false. Can some one please help me.This is my html div.

     <div class="large-12 columns">
                                     <label for="Data_AlternatePhones[i]_IsPrimary">
                                        <input class="toggle_enabled hidden-field" id="Data_AlternatePhones[i]_IsPrimary" name="Data.AlternatePhones[i].IsPrimary" value="true" type="checkbox">
                                        <span class="custom checkbox"></span>
                                        <input name="Data.AlternatePhones[i].IsPrimary" value="false" type="hidden">IsPrimary
                                    </label>

                                </div>

When the checkbox is checked, the page inspector code shows the following html snippet

    <div class="large-12 columns">


                                    <label for="Data_AlternatePhones[i]_IsPrimary">
                                        <input class="toggle_enabled hidden-field" id="Data_AlternatePhones[i]_IsPrimary" name="Data.AlternatePhones[i].IsPrimary" value="true" type="checkbox">
                                        <span class="custom checkbox checked"></span>
                                        <input name="Data.AlternatePhones[i].IsPrimary" value="false" type="hidden">IsPrimary
                                    </label>

                                </div>

When the checkbox is NOT checked, the page inspector code shows the following html snippet

    <div class="large-12 columns">


                                    <label for="Data_AlternatePhones[i]_IsPrimary">
                                        <input class="toggle_enabled hidden-field" id="Data_AlternatePhones[i]_IsPrimary" name="Data.AlternatePhones[i].IsPrimary" value="true" type="checkbox">
                                        <span class="custom checkbox"></span>
                                        <input name="Data.AlternatePhones[i].IsPrimary" value="false" type="hidden">IsPrimary
                                    </label>

                                </div>

My data variable in jQuery code is giving isPrimary = false in both case.

     var data =
            {
                customerGuid: $("#Data_CustomerGuid").val(),
                contactInfoType: type,
                contactInfo: $("#Data_AlternatePhones_"+i+"__PhoneNumber").val(),
                isPrimary: $("#Data_AlternatePhones_" + i + "__IsPrimary").is(':checked'),                   
                contactInfoID: $("#Data_AlternatePhones_"+i+"__ID").val()
            };

Please help me figure this out. Thank you.




How to delete multiple rows from a datagridview by selecting the checkboxes in C#?

I have datagridview and header checkbox to check all the check boxes in the rows in the checkbox column (index of the column for all the check boxes 0). I have following code in the deleted button event:

for (int i = 0; i < datagridview.Rows.Count; i++)
            {
                if (Convert.ToBoolean(datagridview.Rows[i]
                                      .Cells[0].Value) == true)
                {
                    datagridview.Rows.RemoveAt(i);
                }

}

The datagridview.rows.count keeps decreasing as the row deleted but i in the loop keeps increasing. Thus, instead of deleting all the checked rows, it deletes some of them only. It does not delete the one with rows index 0, 1, 2 and so on with the new data in the datagridview as i increasing in the code.




Checkboxes in Xamarin.Forms

I’m trying to make a page in my app where a user selects from a list of choices, then presses done to submit what he has selected. I’m using Xamarin.Forms. I directly thought of using checkboxes to achieve this; but apparently Xamarin.Forms doesn’t have checkboxes . Anyone have any suggestions to achieve this? Thanks!




What type has a spreadsheet checkbox in vba?

I have the following code which is supposed to add a checkbox for every row in a listobject next to it. I want to develop an approval tool, which loads data from a data base and loads it into the listobject. After that i can approve or disapprove the data with the checkbox and save the changes. Since the listobject will have changeing length the checkboxes will need to be added and removed by code.

so here the code:

Sub Approval()
Dim i As Integer
Dim tbl As ListObject
Dim CBcollection As Collection
Dim CB As msforms.CheckBox ' THIS IS WRONG
Dim sht As Worksheet
Dim L As Double, T As Double, H As Double, W As Double
Dim rng As Range

Set sht = Tabelle1
Set tbl = sht.ListObjects("ApprovalTBL")
Set rng = tbl.Range(2, 1).Offset(0, -1)
      W = 10
      H = 10
      L = rng.Left + rng.Width / 2 - W / 2
      T = rng.Top + rng.Height / 2 - H / 2

For i = 1 To tbl.ListRows.Count
      Set CB = sht.OLEObjects.Add(ClassType:="Forms.CheckBox.1", Link:=False, DisplayAsIcon:=False, Left:=L, Top:=T, Width:=W, Height:=H) 
'the line before will give me an error 13 type missmatch
      CBcollection.Add (CB)
      Set rng = rng.Offset(-1, 0)
      T = rng.Top + rng.Height / 2 - H / 2
Next i

End Sub

Now the question:

What type has Checkbox in a normal spreadsheet?

I always use "Option Explicit" and I will always dim my variables to the right type and I do not want to use variant types.




CheckBox being checked but not doing function

I am currently using php loops to spawn in panels from a database. On each of these panels there is a checkbox. When checked it checks all the checkboxes under it in the collapsible panels.

When the check boxes in the panels get checked by the checkbox in the panel header it is meant to run a function which updates my database saying that box is checked. The function works when you down the collapsible panels a check the box manually. But when you check the box from a higher level and check all the boxes bellow it, it doesnt run the onchange function i have put in.

Can anyone help?

Thanks, Kristian

PHP:

foreach ($results3 as $table3) {
        $output_string .= "<div class=\"panel-inner\">\n";
        $output_string .= "<div class=\"row\">\n";
        $output_string .= "<div class=\"col-sm12\">\n";
        $output_string .= "<div class=\"panel-body\">\n";
        $output_string .= "<h4 class=\"panel-title\">\n";
        $output_string .= "<a>$table3[Call_Flow]</a>\n";
        $output_string .= "<input class=\"mycheckbox\" type=\"checkbox\" value=\"$table3[Test_ID]\" onchange=\"adds(tccb$j)\" id=\"tccb$j\"/>\n";
        $output_string .= "</h4>\n";
            $output_string .= "</div>\n";
        $output_string .= "<div id=\"collapseflow$j\" class=\"panel-body collapse\">\n";

HTML:

<div id="check">

    </div>

    <script>
    function adds(id) {

    var value = $(id).val()

        jQuery.ajax({
            url: "selection_update.php",
            data: {"value": value},
            type: "POST",
            dataType: 'json',
                success:function(responce){
                $("#check").html(responce);
            }
        });
    }
    </script>