samedi 31 décembre 2016

PHP MYSQL checkbox search

I am working on a checkbox search. I'm new to PHP. I would appreciate it if someone could help me. Basically the user checks the options required, hits submit and results matching the checkbox options is displayed. The checkboxes have a value of M for Male and F for Female which matches the data in the MYSQL table.

So if a user checks checkbox 'Male' (see code below) all data with 'Male' that have a value of 'M' in the MYSQL table are returned. And any checkboxes not checked should simply be ignored as the user is only interested in the option 'Male' being 'M' (true).

To sum up I only need the search to take into account checkboxes that have been checked and echo which users that has been selected(more like filtering) through PHP.Any help appreciated. Thanks

the table looks like this :

id      name     address    gender    race
-------------------------------------------

1. 1    Lee      NY          M        French
2. 2    James    LA          M        Colombian
3. 3    Kashi    JAPAN       F        Japanese

and i have a form with checkboxes like this :

<form action="shortlist.php" method="post">
 Search: <input name="searchquery" type="text">
 <button name = "myBtn" type="submit" class="btn btn-default">Search</button>
<br/><br/>
  <label for="sel1">Shortlist:</label>
  <select name = "filter" class="form-control" id="sel1">
    <option value="Race">Race</option>
    <option value="Gender">Gender</option>
    <option value="Age">Age</option>
    <option value="Skills">Skills</option>
  </select>
</form>




interacting with checkboxes in a php while loop

Having an issue with my to do list check boxes that are displayed from a php while loop. My JQuery seems to add css class to all my check boxes when i check one of them.

Php function:

function get_tasks(){
    $query = query("SELECT *  FROM tasks");

    confirm($query);

    while($row = fetch_array($query)){

        $task_name = $row['task_name'];
        $task_id = $row['task_id'];
        $task_desc =$row['task_description'];
        $date_created = $row['date_created'];

         $tasks = <<<DELIMETER

        <tr>
        <td><input type="checkbox" class="checkBoxes" name="checkBoxArray" value="{$task_id}"> </td>
        <td> <span class="task_name">{$task_name}</span> </td>
        <td> {$task_desc} </td>
        <td> {$date_created} </td>
        <td> <a href='javascript:void(0)' id="delete" class='btn btn-danger delete_link' rel='{$task_id}' ><span class='glyphicon glyphicon-remove'></span></a></td>   </td>

        </tr>


DELIMETER;

echo $tasks;


    }



}

JQuery code to interact with the check boxes.

<script src="http://ift.tt/2eBd7UN"></script>

<script>
        $(document).ready(function(){  

       $('input:checkbox').change(function(){

          if($(this).is(":checked")){

              $('.task_name').addClass("completed"); //adds strike through to show task is completed.
              $('.delete_link').show();

          } else{

              $('.task_name').removeClass("completed");
              $('.delete_link').hide();



          }

       });

    });

    </script>




How To Check CheckBox From Multiple CheckBoxes On WebPage Using Data Provider(Excel) In Selenium WebDriver with JAVA

Scenario : I am currently automating a form where I am passing all input from excel. It includes textboxes ,checkboxes datepicker etc. Form includes total 15 checkboxes. Now I want my script to check 1 checkbox which is mentioned in excel. I am using TestNG and Apache POI for it. Here is what I have done to get it :

public void EventCreation1(String EventName, String EventTagLine,String EventOrganization,String City,String State,String Country, String EventCategory ,String EventDescription,String Name,String EmailID,String Contact)
    {


        driver.get("WEBPAGE URL");

        driver.findElement(By.xpath(".//*[@id='eventName']")).sendKeys(EventName);
        driver.findElement(By.xpath(".//*[@id='eventTagLine']")).sendKeys(EventTagLine);
        driver.findElement(By.xpath(".//*[@id='organizerName']")).sendKeys(EventOrganization);
        driver.findElement(By.xpath(".//*[@id='eventCity']")).sendKeys(City);
        driver.findElement(By.xpath(".//*[@id='eventState']")).sendKeys(State);
        driver.findElement(By.xpath(".//*[@id='eventCountry']")).sendKeys(Country);

//For Category
List<WebElement> Checkbox = driver.findElements(By.xpath("//input[@type='checkbox']")).getAttribute;

        for(int i=0; i<Checkbox.size();i++ )

        {
            WebElement El =Checkbox.get(i);     
            String id =El.getAttribute("value");
            if(id.equals(EventCategory))
            {
                El.click();

            }
        }

Here // String EventCategory is the Checkbox option I am passing as parameter from excel.

Could you please help in this what is wrong here?

HTML Tag: 


                <div class="section colm colm9">

                    <div class="frm-row">

                        <div class="section colm colm4">

                            <div class="option-group">

                                <label class="option option-blue block">
                                    <input type="checkbox" name="eventType[]" value="TechFest">
                                    <span class="checkbox"></span> TechFest
                                </label>

                                <label class="option option-blue block spacer-t10">
                                    <input type="checkbox" name="eventType[]" value="Cultural Fest">
                                    <span class="checkbox"></span> Cultural Fest
                                </label>

                                <label class="option option-blue block spacer-t10">
                                    <input type="checkbox" name="eventType[]" value="Management Fest">
                                    <span class="checkbox"></span> Management Fest
                                </label>

                                <label class="option option-blue block spacer-t10">
                                    <input type="checkbox" name="eventType[]" value="Sports Fest">
                                    <span class="checkbox"></span> Sports Fest
                                </label>

                                <label class="option option-blue block spacer-t10">
                                    <input type="checkbox" name="eventType[]" value="Workshop">
                                    <span class="checkbox"></span> Workshop
                                </label>

                            </div><!-- end .option-group section -->




vendredi 30 décembre 2016

Influencing secondary radio buttons based on primary checkbox choice

I have one group of checkboxes and one group of radio buttons. They are as follows:

PRIMARY CHECKBOXES

<input class="filter" type="checkbox" id="theme1" name="theme" value="adventure">
<label for="theme1">Adventure</label>
<input class="filter" type="checkbox" id="theme2" name="theme" value="attraction">
<label for="theme2">Attraction</label>
<input class="filter" type="checkbox" id="theme3" name="theme" value="leisure">
<label for="theme3">Leisure</label>
<input class="filter" type="checkbox" id="theme4" name="theme" value="culture">
<label for="theme4">Culture</label>
<input class="filter" type="checkbox" id="theme5" name="theme" value="nature">
<label for="theme5">Nature</label>

SECONDARY RADIO BUTTONS

<input class="filter combo" type="radio" id="combo1" name="combo">
<label for="combo1">Adv Att</label>
<input class="filter combo" type="radio" id="combo2" name="combo">
<label for="combo2">Cul Att</label>
<input class="filter combo" type="radio" id="combo3" name="combo">
<label for="combo3">Adv Nat</label>
<input class="filter combo" type="radio" id="combo4" name="combo">
<label for="combo4">Att Lei</label>

JQUERY CODE

$(':checkbox').change(function() {
    if ($('#theme1').is(":checked") && $('#theme2').is(":checked")) {
        $('#combo1').prop('checked', true);
    }
})
$(':checkbox').change(function() {
    if ($('#theme1').is(":checked")) {
        $('#combo2').prop('checked', true);             
    }
})

By doing the above, there is a slight problem. When I select the Adventure checkbox, the Cul Att radio button gets highlighted. But, when I check the Attraction checkbox along with Adventure checkbox, I'd want the radio button to now be on Adv Att. I have this as a condition on my jquery code above, but it still won't work. What am I doing wrong? Any help is much appreciated!




How do i show an alert if no results founded

i have this code: http://ift.tt/2imd9lG For example i tap in a searchbar something like "asdfdsas" there will be no result founded,how do i show an alert when no results founded,and the same with checkboxes,thanks.

-HTML

    <script src="http://ift.tt/1oMJErh"></script>
<pre id=result> </pre>

<input type="text" id="searchFlowerNames" placeholder="Type a flower name..."><span id="searchResult"></span>

<div class="flowers-wrap">


    <h3 style="font-size:14px; font-weight:normal;">Available Flowers</h3>
    <p style="font-size:12px;"><strong>Filter flowers by colour:</strong></p>
    <form>
        <label style="font-size:12px;">
            <input type="checkbox" name="fl-colour" value="red" id="red" /> Red</label>
        <br>
        <label style="font-size:12px;">
            <input type="checkbox" name="fl-colour" value="yellow" id="yellow" /> Yellow</label>
        <br>
        <label style="font-size:12px;">
            <input type="checkbox" name="fl-colour" value="pink" id="pink" /> Pink</label>
        <br>
        <label style="font-size:12px;">
            <input type="checkbox" name="fl-colour" value="purple" id="purple" /> Purple</label>
        <br>
        <label style="font-size:12px;">
            <input type="checkbox" name="fl-colour" value="green" id="green" /> Green</label>
        <br>
        <label style="font-size:12px;">
            <input type="checkbox" name="fl-colour" value="other" id="other" /> Other</label>
    </form>
    <p style="font-size:12px;"><strong>Filter flowers by size:</strong></p>
    <form>
        <label style="font-size:12px;">
            <input type="checkbox" name="fl-size" value="tiny" id="tiny" /> Tiny</label>
        <br>
        <label style="font-size:12px;">
            <input type="checkbox" name="fl-size" value="small" id="small" /> Small</label>
        <br>
        <label style="font-size:12px;">
            <input type="checkbox" name="fl-size" value="medium" id="medium" /> Medium</label>
        <br>
        <label style="font-size:12px;">
            <input type="checkbox" name="fl-size" value="large" id="large" /> Large</label>
        <br>
        <label style="font-size:12px;">
            <input type="checkbox" name="fl-size" value="giant" id="giant" /> Giant</label>
    </form>

</div>

<div class="continents-wrap">

    <h3 style="font-size:14px; font-weight:normal;">Available Continents</h3>

    <div class="continents" style="font-size:12px;">
        <div>Africa
            <input type="checkbox" name="fl-cont" value="africa" id="africa" />
        </div>
        <div>Europe
            <input type="checkbox" name="fl-cont" value="europe" id="europe" />
        </div>
        <div>Asia
            <input type="checkbox" name="fl-cont" value="asia" id="asia" />
        </div>
        <div>North America
            <input type="checkbox" name="fl-cont" value="north-america" id="north-america" />
        </div>
        <div>South America
            <input type="checkbox" name="fl-cont" value="south-america" id="south-america" />
        </div>
        <div>Antarctica
            <input type="checkbox" name="fl-cont" value="antarctica" id="antarctica" />
        </div>
        <div>Australasia
            <input type="checkbox" name="fl-cont" value="australasia" id="australasia" />
        </div>
    </div>

</div>

<div class="flowers">
    <div class="flower" data-id="aloe" data-category="green small medium africa">Aloe</div>
    <div class="flower" data-id="lavendar" data-category="purple green medium africa europe">Lavender</div>
    <div class="flower" data-id="stinging-nettle" data-category="green large africa europe asia">Stinging Nettle</div>
    <div class="flower" data-id="gorse" data-category="green yellow large europe">Gorse</div>
    <div class="flower" data-id="hemp" data-category="green large asia">Hemp</div>
    <div class="flower" data-id="titan-arum" data-category="purple other giant asia">Titan Arum</div>
    <div class="flower" data-id="golden-wattle" data-category="green yellow large australasia">Golden Wattle</div>
    <div class="flower" data-id="purple-prairie-clover" data-category="purple green other medium north-america">Purple Prairie Clover</div>
    <div class="flower" data-id="camellia" data-category="pink other large north-america">Camellia</div>
    <div class="flower" data-id="scarlet-carnation" data-category="red medium north-america">Scarlet Carnation</div>
    <div class="flower" data-id="indian-paintbrush" data-category="red medium north-america">Indian Paintbrush</div>
    <div class="flower" data-id="moss-verbena" data-category="purple other small south-america">Moss Verbena</div>
    <div class="flower" data-id="climbing-dayflower" data-category="blue tiny south-america">Climbing Dayflower</div>
    <div class="flower" data-id="antarctic-pearlwort" data-category="green yellow large antarctica">Antarctic Pearlwort</div>
</div>

-CSS

    body {
  font-family: 'Arial';
  color: #646464;
}

.continents-wrap {
  float: left;
  width: 20%;
  margin: 0 5% 0 0;
  padding: 0;
}

.flowers-wrap {
  float: left;
  width: 20%;
  margin: 0 5% 0 0;
  padding: 0;
  position: relative;
}

.flowers {
  float: left;
  width: 50%;
}

.flowers div {
  float: left;
  width: 90%;
  height: 68px;
  line-height: 68px;
  padding: 0 5%;
  background: #eee;
  margin: 0 0 1px;
  position: relative;
}


-JS

var $filterCheckboxes = $('input[type="checkbox"]');

$filterCheckboxes.on('change', function() {

    var selectedFilters = {};

    $filterCheckboxes.filter(':checked').each(function() {

        if (!selectedFilters.hasOwnProperty(this.name)) {
            selectedFilters[this.name] = [];
        }

        selectedFilters[this.name].push(this.value);

    });

    // create a collection containing all of the filterable elements
    var $filteredResults = $('.flower');

    // loop over the selected filter name -> (array) values pairs
    $.each(selectedFilters, function(name, filterValues) {

        // filter each .flower element
        $filteredResults = $filteredResults.filter(function() {

            var matched = false,
                currentFilterValues = $(this).data('category').split(' ');

            // loop over each category value in the current .flower's data-category
            $.each(currentFilterValues, function(_, currentFilterValue) {

                // if the current category exists in the selected filters array
                // set matched to true, and stop looping. as we're ORing in each
                // set of filters, we only need to match once

                if ($.inArray(currentFilterValue, filterValues) != -1) {
                    matched = true;
                    return false;
                }
            });

            // if matched is true the current .flower element is returned
            return matched;

        });
    });

    $('.flower').hide().filter($filteredResults).show();



});


var flowerArray = [];
$(".flower").each(function(){
    flowerArray.push($(this).html().toLowerCase());
});
//console.log(flowerArray);


$("#searchFlowerNames").on("input",function(){
    var searchInput = $(this).val().toLowerCase();
    $("input[name='fl-colour']").attr("checked",false);
    $("input[name='fl-size']").attr("checked",false);
    $("input[name='fl-cont']").attr("checked",false);

    if(searchInput!=""){
        $(".flower").hide(); 
        $(".flower").each(function(){

            // We have a match.
            if($(this).html().toLowerCase().indexOf(searchInput) != -1){
                $(this).show();

                // To check the relevant checkboxes, have to get the category of this match.
                var thisFlowerData = $(this).data("category").toLowerCase().split(" ");
                //console.log(thisFlowerData);

                // Set the flower color checkboxes
                $("input[name='fl-colour']").each(function(){
                    if(thisFlowerData.indexOf($(this).val().toLowerCase()) != -1){
                        $(this).prop("checked",true);
                        //console.log($(this).val());
                    }
                });

                // Set the flower size checkboxes
                $("input[name='fl-size']").each(function(){
                    if(thisFlowerData.indexOf($(this).val().toLowerCase()) != -1){
                        $(this).prop("checked",true);
                        //console.log($(this).val());
                    }
                });

                // Set the flower continent checkboxes
                $("input[name='fl-cont']").each(function(){
                    if(thisFlowerData.indexOf($(this).val().toLowerCase()) != -1){
                        $(this).prop("checked",true);
                        //console.log($(this).val());
                    }
                });
            }
        });
    }else{
        $(".flower").show(); 
    }
});




Checkbox submits "value" no matter what

The simplest things........

I have a form with two separate checkboxes. There's other stuff too, but basically it's this.

<form>
  <label style="font-size: 20px; width: 120px">Option 1</span> <input type="checkbox" name="selection_1" id="selection_1" style="width: 25px" value="1"/></label>
  <label style="font-size: 20px; width: 120px">Option 2</span> <input type="checkbox" name="selection_2" id="selection_2" style="width: 25px" value="2"/></label>
</form>

Every time I submit the form, both checkboxes are submitted as if they're checked. This happens even if neither or only one is selected. $_POST['selection_1'] is always ending up as 1 and $_POST['selection_2'] is always ending up as 2.

What am I missing here?




Redux Form - Checkbox with a default value and set it to be disabled

I'd like to confirm if this structure is right.

I need to set default value for the checkbox, so I've used the checked={input.value}. I also need to set it to be disabled, then I've passed the disabled prop:

// Using the Checkbox component  
<Field
  name="completed"
  label="Completed"
  disabled={this.props.disableCompleted}
  component={Checkbox}
/>

function Checkbox({ input, label, disabled }) {
  return (
    <div className="form-group">
      <label className="mt-checkbox">
        <input 
          type="checkbox" 
          disabled={disabled} 
          checked={input.value} 
          {...input} /> {label}
        <span></span>
      </label>
    </div>
  );
}

Is there any better way to do this?




Div changes background color when checkbox is checked

I'm still learning jquery and how to put it all together but I have this code set up in a shopping list:

<div class="AddCheckedWrapper">
    <span>Check to Add to Cart</span>
    <input name="atcuid" type="checkbox">
</div>

How I want this to work is that clicking .AddCheckedWrapper checks the checkbox and clicking it again unchecks it. Then, if the box is checked .AddCheckedWrapper background changes to blue. And if it's not checked then .AddCheckedWrapper background changes pink. The issue I'm having though is that since it's a list, there's more than one .AddCheckedWrapper so I know $(this) will have to be used somehow. I also have a quantity box that'll check the checkbox if you change what's in it. So if I change the number in the quantity box no matter it'll check the checkbox. So the background colors have to be in effect based off of the check box being checked or not, and that's where I'm having trouble.




Boostrap multiselct dropdown to have multiple selected values in prior

I have an issue to get the multiselect dropdown selected based on the data. This is update action. When I go to update the roles I need this multislect to have previously checked box to be checked once I enter the page. I am doing in the below method as code pasted.

jquery Code

$(".checkbox-val").hide();
    var count = 1;
    if(count == 1){
    $(".checkbox-val").hide();
        var a = "["+$(".checkbox-val").text()+"]";
        var arr = a.split(",");

        console.log(a);

        $("#lstFruit").val(a); 
        alert(a);
         $("#lstFruit").multiselect({
            includeSelectAllOption: false,
            numberDisplayed: 0,
            enableFiltering: true,
        });
         $("#lstFruit").multiselect("refresh");

    }

and my div code from where I am retrieving the text

  for ($i=0; $i < $count; $i++){ ?>
              <div class="checkbox-val" style="font-size: 0px;"><?php echo  '"'.$user1[$i].'"'.',';?> </div>
         <?php } ?>

  • When I alert or log "var a" I get this output ["Risk Assessor", "Risk Manager",].
  • When I put the same content in

    $("#lstFruit").val(["Risk Assessor", "Risk Manager",]);

  • With above code I get selected checkbox as expected.

  • Instead of the above code I use variable a in place of the array above.

    $("#lstFruit").val(a);

What can I do to achieve what I want. Is there any alternative for this?




Repeated selecting of checkboxs based on value

Using Jquery I have code that works to select all the checkboxes of the same value as the checkboxes that is selected. It also disables all checkboxes on the same row as the checkbox that is selected (the checkboxes are within a table).

This is all great. However it is slightly incomplete, and the last piece of the puzzle is eluding me. Checkboxes on the rows that are disabled are, by definition, disabled. However, it would be perfect if all checkboxes with the same value as those disabled were also disabled. This is to prevent users from selecting incompatible items (there's also a server side measure to prevent this, but client side is so much more pretty and user-friendly).

JSFiddle: http://ift.tt/2ikR5Ii $(".chkbox").on('change', function() {

    var currentObj = $(this);
    var val = $(this).val();
    if ($(this).is(":checked")) {

        $(":checkbox[value='" + val + "']").prop("checked", true);
        $(this)
            .closest("tr")
            .find(".chkbox").attr("disabled", "disabled");
        $(currentObj).removeAttr("disabled");
        $(":checkbox[value='" + val + "']")
            .closest("tr")
            .find(".chkbox").attr("disabled", "disabled");
        $(":checkbox[value='" + val + "']").removeAttr("disabled");
    } else {
        $(":checkbox[value='" + val + "']").prop("checked", false);
        $(":checkbox[value='" + val + "']")
            .closest("tr")
            .find(".chkbox").removeAttr('disabled');;

    }

});




select all checkboxes does not work on next page in jquery datatables

I am using jquery datatables. I want to add select all column with checkboxes. So when I click on 'select all' check box all the checkboxes on that page should get selected.

I am using the following code

<table id="myTable" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th> Name</th>
            <th> Type</th>
            <th> Details</th>
            <th>Select <input type="checkbox" name="select_all" value="1" id="select-all"></th>
        </tr>
    </thead>
    <tbody>
        <?php foreach ($test as $data) { ?>
        <tr>
            <td><?php echo $data->name; ?></td>
            <td><?php echo $data->type; ?></td>
            <td><a href="/details">view details</a></td>
            <td><input type="checkbox" name="manuf[]" class="sub_chk" data-id="<?php echo $data->id; ?>"></td>


        </tr>
        <?php } ?>
    </tbody>
</table>
<script>
$(document).ready(function(){
$('#myTable').DataTable();
});

$('#select-all').on('click', function(e) {
if($(this).is(':checked',true))  
{
    $(".sub_chk").prop('checked', true);  
}  
else  
{  
    $(".sub_chk").prop('checked',false);  
}  
});
</script>

The above code works for the first page of the datatable But if I select the second page and if I select 'Select all' checkbox, it takes me to the first page instead of selecting the checkboxes in the second page.

How can I fix this..




Count all checked checkbox and display the first value

I need help on my php program.

I have 2 forms inside my testing.php

  • Main form named "mainform"
  • the other Form is with checkbox named "modalForm"

My program works like this. If you click the disabled textbox, a modal will pop-up containing the form with checkbox. If only 1 of the checkbox were check I'm gonna display the value of it on my disabled textbox otherwise if more than 2 were check I will display the value "Multiple" on the disabled textbox.

Here is my look a like code

testing.php

<form method="post" name="mainform" action="">
        <label>TestLabel</label>
        <a href="#modal"> <!-- when the input textbox was clicked, modal will pop up -->
            <input disabled type="text" name="test" placeholder="test" value="">
        </a>
    </form>

    <form method="post" name="modalForm" id="modalForm" action="testing.php">
        <div class="modalwrapper" id="modal">   <!-- modal -->
                <div class="modalcontainer">    
                    <div class="modalcol1">
                        <label>Test 1</label>
                        <input type="checkbox" name="test_modal[]" value="mark">
                        <div class="clear"></div>
                        <label>Test 2</label>
                        <input type="checkbox" name="test_modal[]" value="joe">
                        <div class="clear"></div>
                        <label>Test 3</label>
                        <input type="checkbox" name="test_modal[]" value="kevin">
                        <div class="clear"></div>
                        <label>Test 4</label>
                        <input type="checkbox" name="test_modal[]" value="michael">
                        <div class="clear"></div>
                        <label>Test 5</label>
                        <input type="checkbox" name="test_modal[]" value="jordan">
                        <div class="clear"></div>

                        <div class="savebutton">
                            <input class="btn1" type="submit" value="Submit"/>
                        </div>
                    </div>
                </div>
            <div class="overlay"></div>
        </div>      
    </form>

styles.css

/* modal layout */
    .modalwrapper {
        top: 0;
        left: 0;
        opacity: 0;
        position: absolute;
        visibility: hidden;
        box-shadow: 0 3px 7px rgba(0,0,0,.25);
        box-sizing: border-box;
        transition: all .4s ease-in-out;
        -webkit-transition: all .4s ease-in-out;
        -moz-transition: all .4s ease-in-out;
    }

    .modalwrapper:target {
        opacity: 1;
        visibility: visible
    }

    .overlay {
        background-color: #000;
        background: rgba(0,0,0,.8);
        height: 100%;
        left: 0;
        position: fixed;
        top: 0;
        width: 100%;
        z-index: 1;
    }

    .modalcontainer {
        display: table;
        background-color: #777;
        position: relative;
        z-index: 100;
        color: #fff;
        padding: 5px;
    }

    .modalcol1 { display: table-cell; }

    .clear { clear: both; }

    .modalwrapper input[type=checkbox] {
        float: right;
        margin-right: 20px;
    }

    .savebutton input[type=submit] {
        float: right;
        background-color: maroon;
        color: #fff;
        border: none;
        padding: 5px 10px;
        margin-top: 5px;
        margin-right: 20px;
    }
    /* modal layout ends here */

Hope you guys can help me. I wanna know how can I pass the value of the checkboxes on my mainform . Thank you so much in advance.




Not managed to get value for unchecked checkbox

First, don't treat this as duplicate since I do a few try & error, as well research before asking. I intended to post value from jquery including unchecked checkbox. I've tried many ways but still didn't manage to get it works, either due to structure of my code or else. Here is one of the attempt I try currently:

$('#l_sync_ul').click(function () {
                   if ($('#l_sync_ul').prop("checked") == undefined) {
                      $('#l_sync_ul').after('<input type="hidden" name="' + $('#l_sync_ul').attr("l_sync_ul") + '" value=off>')
                   } else {
                      $('#l_sync_ul').next().remove();
                   }
                }
          );

Here is the HTML file related:

<input name="l_sync_ul" id="l_sync_ul" onclick="toggle_tip('ul_dept')" type="checkbox">

Just ignore the 'onclicks' attribute since I'm using it for toggle the table.




jeudi 29 décembre 2016

Checkbox's event handler not being triggered

I'm using textboxes to store certain values, but only if a corresponding checkbox is clicked. Otherwise the textboxes are disabled. The textboxes and the checkboxes are dynamically generated. So, I've used the on method. The text boxes are $text, $qnty, $unit and $price, each followed by the row id. The associated checkbox is called selected[] and has a class of itemCbox. For that, my jQuery code is:

$("#listDB").on("click", ".itemCbox", function(event) {
    var id = this.value;
    $text = $("#text"+id);
    $qnty = $("#qnty"+id);
    $unit = $("#unit"+id);
    $price = $("#price"+id);

    if ($(this).is(':checked')) 
    {
        $text.css('background-color', '#fff');
        $text.attr('disabled', false);
        $qnty.attr('disabled', false);
        $unit.attr('disabled', false);
        $price.attr('disabled', false);
    }
    else
    {
        $text.css('background-color', 'rgba(0,0,0,0)');
        $text.attr('disabled', true);
        $qnty.attr('disabled', true);
        $unit.attr('disabled', true);
        $price.attr('disabled', true);
        $text.val('');
        $qnty.val('--');
        $unit.val('--');
        $price.val('0.00');
    }
});

On selecting the cancel option in a dialog, I want the checkboxes to automatically be unchecked, and the corresponding textboxes to be disabled. To acheive this, further down, I use the code:

$("#cancelInsert").click(function(event){
    $("input:checked[name='selected[]']").each(function () {
        $(this).attr('checked', false);;
        $(this).trigger('click');
    });
});

This kinda works - the checkboxes are unchecked, but the associated textboxes are not disabled. Why is this? Is the corresponding event handler $("#listDB").on("click", ".itemCbox", function(event) {...} not firing? If so, why and how do I fix this?

I'm guessing this is because the event is only activated when the conditions for .on("click", ".itemCbox" are met, and simply triggering click is not enough. Is that correct?


Code Dump

My entire HTML is:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>SomuFinance - Add Items to Bill</title>
    <link rel="stylesheet" type="text/css" href="../../jquery-ui-1.12.1/jquery-ui.min.css">
    <link rel="stylesheet" type="text/css" href="../../css/indexStyle.css">
    <script src="../../scripts/jquery-3.1.1.min.js"></script>
    <script src="../../scripts/jquery.validate.min.js"></script>
    <script src="../../jquery-ui-1.12.1/jquery-ui.min.js"></script>
    <script src="../../scripts/moment.js"></script>
    <script src="../../scripts/addToBill.js"></script>
</head>
<body>
    <form id="list" method="post" action="addToBill.php">
        <div id="container">
            <h1>Add Items</h1>
            <input type="button" class="button" name="back" id="back" value="&larr; Go Back to Bill" />
            <select name="category_selector" id="category_selector">
                <option value="All" selected>All</option>
            </select>
            <input type="button" class="button" name="add" id="add" value="Add Selected Items" />
            <input type="button" class="button" name="edit" id="edit" value="Edit and Add" />
            <input type="button" id="showSearch" class="button" name="search" value="Search" />
            <input type="hidden" id="action" name="action">
            <table id="listDB">
                <tr>
                    <th>Select</th>
                    <th>ID</th>
                    <th>Sl. No</th>
                    <th>Item</th>
                    <th>Quantity</th>
                    <th>Unit</th>
                    <th>Price Based On</th>
                    <th>MRP</th>
                    <th>Seller's Price</th>
                    <th class="rightBorder">Last Updated On</th>
                    <th>Quantity Factor</th>
                    <th>Quantity</th>
                    <th>Unit</th>
                    <th>Price</th>
                </tr>
            </table>
        </div>
    </form>

    <div class="dialogBG">
        <div id="insertMessage" class="dialog">
            <div class="closeDialog"></div>
        </div>
    </div>

    <div class="dialogBG">
        <div id="editItemContainer" class="dialog">
            <div class="closeDialog"></div>
            <h1>Edit Item</h1>
            <form id="data" method="post" action="viewData.php">
                <div>
                    <input type="hidden" id="id" name="id" required>
                    <div class="inp">
                        <label for="shop">ID : </label>
                        <input type="text" id="id_disp" name="id_disp" required disabled>
                    </div> <br>
                    <div class="inp">
                        <label for="shop">Shop : </label>
                        <input type="text" id="shop" name="shop" required readonly>
                    </div> <br>
                    <div class="inp">
                        <label for="category">Category : </label>
                        <input type="text" id="category" name="category" required readonly>
                    </div> <br>
                    <div class="inp">
                        <label for="item">Item : </label>
                        <input type="text" id="item" name="item" required readonly>
                    </div> <br>
                    <div class="inp">
                        <label for="qnty">Quantity : </label>
                        <input type="text" id="qnty" name="qnty" required readonly>
                    </div> <br>
                    <div class="inp">
                        <label for="unit">Unit : </label>
                        <input type="text" id="unit" name="unit" required readonly>
                    </div> <br>
                    <div class="inp">
                        <label for="price_based_on">Price based on : </label>
                        <input type="text" id="price_based_on" name="price_based_on" readonly>
                    </div> <br>
                    <hr>
                    <div class="inp" class=".centerAligned">
                        <label for="editPrice">Edit Price and Date : </label>
                        <input type="checkbox" id="editPrice" value="editPrice" name="editPrice">
                    </div>
                    <hr>
                    <div class="inp">
                        <label for="mrp">MRP (₹) : </label>
                        <input type="text" id="mrp" name="mrp" required readonly>
                    </div> <br>
                    <div class="inp">
                        <label for="sellers_price">Seller's Price (₹) : </label>
                        <input type="text" id="sellers_price" name="sellers_price" required readonly>
                    </div> <br>
                    <div class="inp">
                        <label for="last_updated_on">Last Updated on : </label>
                        <input type="date" id="last_updated_on" name="last_updated_on" required readonly>
                    </div>
                    <hr>
                    <div class="inp">
                        <label for="qf">Quantity Factor : </label>
                        <input type="text" id="qf" name="qf" required>
                    </div> <br>
                    <div class="inp">
                        <label for="calQnty">Calculated Quantity : </label>
                        <input type="text" id="calQnty" name="calQnty" required readonly>
                    </div> <br>
                    <div class="inp">
                        <label for="calUnit">Calculated Unit : </label>
                        <input type="text" id="calUnit" name="calUnit" required readonly>
                    </div> <br>
                    <div class="inp">
                        <label for="calPrice">Calculated Price (₹) : </label>
                        <input type="text" id="calPrice" name="calPrice" required readonly>
                    </div> <br>
                </div>
                <div class="inp">
                    <input id="insertBill" class="dialogButton" type="button" name="insertBill" value="Insert Item to Bill">
                    <input type="button" class="dialogButton cancelButton" name="cancelInsert" id="cancelInsert" value="Cancel" />
                </div>
                <div id="message"></div>
            </form>
        </div>
    </div>

    <div class="dialogBG">
        <div id="searchDialog" class="dialog">
            <div class="closeDialog"></div>
            <form id="searchForm" name="searchForm" method="post" action="addToBill.php">
                <h1>Search Criteria</h1>
                <div class="inp">
                    <label for="group">Search in : </label>
                    <select id="field" name="field">
                        <option value="id">ID</option>
                        <option value="shop">Shop</option>
                        <option value="item">Item</option>
                        <option value="qnty">Quantity+Unit</option>
                        <option value="price_based_on">Price Based On</option>
                        <option value="MRP">MRP</option>
                        <option value="sellers_price">Seller's Price</option>
                        <option value="last_updated_on">Last Updated On</option>
                    </select>
                </div> <br>
                <div class="inp" id="criteriaDiv">
                    <label for="criteria">Search For : </label>
                    <input type="text" id="criteria" name="criteria" required>
                </div> <br>
                <div class="inp" id="unitDiv">
                    <label for="unitCriteria">Unit : </label>
                    <input type="text" id="unitCriteria" name="unitCriteria" required>
                </div> <br>
                <div class="inp" id="dateDiv">
                    <label for="dateCriteria">Last Updated On : </label>
                    <input type="date" id="dateCriteria" name="dateCriteria" required>
                </div> <br>
                <input type="button" id="search" class="dialogButton" name="search" value="Search" />
                <input type="button" class="dialogButton cancelButton" name="cancelSearch" value="Cancel" />
            </form>
        </div>
    </div>
</body>
</html>

The code to generate the dynamically generated checkboxes and textboxes are:

$("#category_selector").change(function(event) {
    if($search!==null)
    {
        $search.remove();
        $search = null;
    }
    $("#listDB").css('display', 'none');
    $("#listDB").find(".catHead").remove();
    $("#listDB").find(".data").remove();
    if($(this).val()=="Search")
        if(!$("#searchDialog").is(":visible"))
        {
            $("#showSearch").trigger('click');
            return;
        }

    $("#action").val('getList');
    var data = $("#list :input").serialize();
    $.post($("#list").attr('action'), data, function(json) 
    {
        if(json.listArr.length>0)
        {
            $.each(json.listArr, function() {
                var $tr = $('<tr>', {
                    class   : "catHead",
                });
                var $td = $('<td>', {
                    class   : "catHead",
                    colspan : 14,
                    text    : this.category
                });
                $("#listDB").append($tr.append($td));

                $.each(this.value, function() {
                    var $tr = $('<tr>',{
                        class : "data"
                    });

                    var $td = $('<td>', {
                        html    : '<input type="checkbox" class="itemCbox" id="selected[]" value="'+this.id+'" name="selected[]" /></td>'
                    });$tr.append($td);
                    $td = $('<td>', {
                        text    : this.id
                    });$tr.append($td);
                    $td = $('<td>', {
                        text    : this.catCount
                    });$tr.append($td);
                    $td = $('<td>', {
                        class : "leftAligned",
                        text    : this.item
                    });$tr.append($td);
                    $td = $('<td>', {
                        class   : "qnty",
                        text    : this.qnty
                    });$tr.append($td);
                    $td = $('<td>', {
                        class   : "unit",
                        text    : this.unit
                    });$tr.append($td);
                    $td = $('<td>', {
                        class   : "pbo",
                        text    : this.price_based_on
                    });$tr.append($td);
                    $td = $('<td>', {
                        class   : "rightAligned",
                        text    : "₹"+this.mrp
                    });$tr.append($td);
                    $td = $('<td>', {
                        class   : "rightAligned",
                        text    : "₹"+this.sellers_price
                    });$tr.append($td);
                    var formattedDate = new Date(this.last_updated_on);
                    var d = formattedDate.getDate();
                    var m =  formattedDate.getMonth();
                    m += 1;  // JavaScript months are 0-11
                    var y = formattedDate.getFullYear();
                    var date = (d<10?"0":"")+d+"-"+(m<10?"0":"")+m+"-"+y;
                    $td = $('<td>', {
                        class   : "rightBorder",
                        text    : date
                    });$tr.append($td);

                    var $qf = $("<input>",{
                        type    : "text",
                        class   : "qfStyle",
                        id      : "text"+this.id,
                        name    : "text"+this.id,
                        disabled: true
                    });$td = $("<td>");$td.append($qf);$tr.append($td);

                    var $qnty = $("<input>",{
                        type    : "text",
                        class   : "textStyle",
                        id      : "qnty"+this.id,
                        name    : "qnty"+this.id,
                        value   : "--",
                        disabled: true,
                        readonly: true
                    });$td = $("<td>");$td.append($qnty);$tr.append($td);

                    var $unit = $("<input>",{
                        type    : "text",
                        class   : "textStyle",
                        id      : "unit"+this.id,
                        name    : "unit"+this.id,
                        value    : "--",
                        disabled: true,
                        readonly: true
                    });$td = $("<td>");$td.append($unit);$tr.append($td);

                    var $price = $("<input>",{
                        type    : "text",
                        class   : "textStyle rightAligned",
                        id      : "price"+this.id,
                        name    : "price"+this.id,
                        value   : "0.00",
                        disabled: true,
                        readonly: true
                    });$td = $("<td>");$td.append($price);$tr.append($td);

                    $("#listDB").append($tr);
                });
            });
        }
    },"json");
    $("#listDB").fadeIn(500);
}); 




Php update database if checkbox is not checked

so I have a dynamically generated table

<tr>
    <td><?php echo $row['RequestID']?></td>
    <td><?php echo $row['FirstName'] . " " . $row['LastName']?></td>
    <td><?php echo $row['DateRequested']?></td>
    <td><?php echo $row['DateNeeded']?></td>
    <td><?php echo $row['TotalPrice']?></td>
    <td><?php echo $row['Company']?></td>
    <td><?php echo $row['Account']?></td>
    <td><?php echo $row['Brand']?></td>
    <td><?php echo $quantity?></td>
    <td><input type="checkbox" name="bill[]" value=<?php echo '"' . $row['RequestID'] . '"'; if($row['BillBack'] == "1") {echo "checked='checked'"; } ?></td>
</tr>

and I want to update the database when a row is checked or unchecked.

if(isset($_POST['submit'])){//to run PHP script on submit
    if(!empty($_POST['bill'])){
    // Loop to store and display values of individual checked checkbox.
    foreach($_POST['bill'] as $selected){
    echo "hello";
    $sql2 = "UPDATE Requests SET BillBack = '1' WHERE RequestID = '$selected'";
    $result2 = $conn->query($sql2);

    }} elseif(empty($_POST['bill'])){
    // Loop to store and display values of individual checked checkbox.
    foreach($_POST['bill'] as $selected){
    echo "hello";
    $sql2 = "UPDATE Requests SET BillBack = '0' WHERE RequestID = '$selected'";
    $result2 = $conn->query($sql2);
    }}

         }

Now. The if statement works like a charm. For every checked checkbox on a submit, that record gets updated. The issue comes with unchecking the checkboxes. As you can see, checked boxes are found by finding what is not empty. But, when I delete that exclamation point, it does not effectively do the opposite. It also doesn't work as it's own if statement, as a straight else statement, and checking for !isset. Is this because of how the inputs are deemed checked? is there a syntax error? I've done about 5 hours of error checking, googling, and the like... and I can't find shit. Thanks guys




C# MySql ChangeDatagGridView Information? Boolean

I have wrote a simple program that populates a datagrid from mysql.

In one of my columns I have a Boolean (0 or 1)

Once the datagrid populates with the query I have check boxes for the boolean.

Does anyone know how to use a function when you check the check boxes for the boolean? (This is to send an update of just the boolean of the column.)

The reason I am having an issue with this is simply because the datagrid does not populate until I run the application. Therefor I cannot figure out how to change it while in visual studio.

Any Help would be greatful.




How to unit test the checkbox in Angular2

I have a sample code for checkbox written with Angular2.

<div class="col-sm-7 align-left" *ngIf="Some-Condtion">
    <input type="checkbox" id="mob_Q1" value="Q1" />
    <label for="mob_Q1">Express</label>
</div>

I want to unit test the above checkbox. Like I want to recognize the checkbox and test whether it is check-able. How do I unit test this with Karma Jasmine?




How can I check each line in a datagridview to see if a checkbox is checked and then delete those which are checked

I've been looking around on here and other sites to try and find a solution to my problem. As the title says I want to loop and check each line in the datagrid to see if the checkbox is check if so then that row is deleted. Also this program is connected to a Access DB. This is the code which I have so far:

 For Each oRow As DataGridViewRow In dvgSupport.Rows
        If oRow.Cells("completeCheck").Value = True Then
            TblSupportSystemBindingSource.RemoveCurrent()
            Try
                TblSupportSystemBindingSource.EndEdit()
                TblSupportSystemTableAdapter.Update(EntireDBDataSet.tblSupportSystem)
                MsgBox("Data has been saved", vbOKOnly, "Success")
            Catch ex As Exception
                MsgBox("An error has occured", vbOKOnly, "Error")
            End Try
        Else
            MsgBox("n")
        End If
    Next

I believe that is only checking to see if all the checkboxes within the designated column are checked then it will remove the current however if only one is checkbox is checked then nothing will happen. Any help would be much appreciated.

TIA




How to check if check box has been checked in php

I have check boxes which display information from a database and was wonder how I would check if one of the radio buttons has been checked once the user clicks submit.

Here is my code.

  <?php 

                $query1 = "SELECT town FROM place WHERE ID = 1";

    
      $result1 = mysqli_query($con, $query1) or die("Invalid Query");

      while($row1 = mysqli_fetch_assoc($result1)){ 
        
        $town = $row1["town"];


echo "<input type=\"checkbox\" name=\"town\" value=\"$town\" />$town </br>";
        
        }

        $query2 = "SELECT town FROM place WHERE ID = 2";

    
      $result2 = mysqli_query($con, $query2) or die("Invalid Query");

      while($row2 = mysqli_fetch_assoc($result2)){ 
        
        $town = $row2["town"];


echo "<input type=\"checkbox\" name=\"town\" value=\"$town\" />$town </br>";
        
        
        }

                $query3 = "SELECT town FROM place WHERE ID = 3";

    
      $result3 = mysqli_query($con, $query3) or die("Invalid Query");

      while($row3 = mysqli_fetch_assoc($result3)){ 
        
        $town = $row3["town"];


echo "<input type=\"checkbox\" name=\"town\" value=\"$town\" />$town </br>";

        }



Allow onclick event on TR element but prevent the event in the checkbox

How can I allow onClick event on TR element but prevent the event in the checkbox? The checkboxes are children of TDs of TRs in table.

What I did in this problem is adding onClick on all TDs but not in the TDs of the checkbox.

Is there a better approach for this problem?




mercredi 28 décembre 2016

add checkbox in UIAlertController

I need to add a check box in the alert asking if I should show this message again. I came across various examples where a button or a text field was added in the controller but didn't see a checkbox anywhere. UIAlertView is deprecated above version 9 so I don't want to use that.

UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil message:@"Should I remind?" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *yesAction = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  [self goToAddReminderView];
}];
UIAlertAction *noAction = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
[self.navigationController popViewControllerAnimated:YES];
}];

[alert addAction:yesAction];
[alert addAction:noAction];

[self presentViewController:alert animated:YES completion:nil];

I would appraciate an example.




Limiting Checked in the datagridview and get data from it to label

Please help me. I have some problem on my code. I have a Datagridview with Checkbox column in it. My system is a library system. i want the user to borrow only 2 books. and my problem is. 1. I want to limit the user to checked only to 2. 2. And i want to get some data for example the book title and the author to a label.

Please help me.

Public Sub BorrowBook()

    Dim Message As String = String.Empty
Dim Message1 As String = String.Empty
Dim Message2 As String = String.Empty
Dim Message3 As String = String.Empty
Dim Message4 As String = String.Empty
    Dim Message5 As String = String.Empty

    For Each row As DataGridViewRow In Form5.DataGridView1.Rows
        Dim isSelected As Boolean = Convert.ToBoolean(row.Cells("checkBoxColumn").Value)
        isSelected += 1
        If isSelected = 1 Then
            Message = row.Cells("BookID").Value.ToString()
            Message1 = row.Cells("CallNumber").Value.ToString()
            Message2 = row.Cells("Title").Value.ToString()

        ElseIf isSelected = 2 Then
            Message3 = row.Cells("BookID").Value.ToString()
            Message4 = row.Cells("CallNumber").Value.ToString()
            Message5 = row.Cells("Title").Value.ToString()

        End If
    Next
    Form5.Label17.Text = Message
    Form5.Label25.Text = Message1
    Form5.Label21.Text = Message2
    Form5.Label20.Text = Message3
    Form5.Label26.Text = Message4
    Form5.Label19.Text = Message5
End Sub




The input value of checkbox array can't pass to POST on my php site

I have a problem on passing the input value of checkbox array to POST but it doesn't work at all. The following codes are about how I pass the input value of checkbox array to POST. The database and the server work fine as I tried only the value instead of passing variables and it works in this case and it must be the problem of the coding part. I tried several approaches from others but it didn't work at all. Does anyone have any idea? Thanks!

The checkbox part in input form:

        <fieldset>
    <legend>Categories</legend>
    <?php
    $stmt2 = $db->query('SELECT catID, catTitle FROM blog_cats ORDER BY catTitle');
    while($row2 = $stmt2->fetch()){

        $stmt3 = $db->prepare('SELECT catID FROM blog_cat_cats WHERE catID=:catID AND postID=:postID');
        $stmt3->execute(array(':catID'=> $row2['catID'],':postID'=> $row['postID']));
        $row3 = $stmt3->fetch();

        if($row3['catID'] == $row2['catID']){
            $checked = 'checked="checked"';
        } else {
            $checked = '';

        }
        echo "<input type='checkbox' name='catIDlist[]' value='".$row2['catID']."' $checked> ".$row2['catTitle']."<br/>";
    }
    ?>
    </fieldset>

The POST part to retrieve the value from the checkbox

    if(isset($_POST['submit'])){
    $_POST = array_map( 'stripslashes', $_POST);

    //collect form data
    extract($_POST);

            $stmt = $db->prepare('DELETE FROM blog_cat_cats WHERE postID = :postID');
            $stmt->execute(array(':postID' => $postID));

            if(is_array($catIDlist)){
                foreach($_POST['catIDlist'] as $catvalue){
                    $stmt = $db->prepare('INSERT INTO blog_cat_cats (postID, catID) VALUES (:postID, :catID)');
                    $stmt->execute(array(
                        ':postID' => $postID, 
                        ':catID' => $catvalue
                    ));
                 }
             }




Getting values from checkboxes in Laravel 5

I'm working on a quote request form on my site and need some help with functionality. I'm trying to get the values from a set of checkboxes that I passed to the view; like so:

Controller (getQuote)

public function getQuote()
    {

      $services = array(
        'Accept donations',
        'Update website on your own',
        'E-Commerce',
        ...
      );

        return view('pages.quote')->withServices($services);

    }

Controller (postQuote)

public function postQuote(Request $request)
    {
      $this->validate($request, [
        'services' => 'required|array',
        ...
      ]);


      $data = array(
        'services' => $request->service,
        ...
      );

      $data['services_checked'] = Input::get('service');
      if(is_array($services_checked))
      {
      }

      Mail::send('emails.quote', $data, function($message) use ($data){
        $message->from($data['email']);
        $message->to('hi@sogenius.io');
        $message->subject('New quote request for ' .  $data['firstname'] . ' ' . $data['lastname']);

      });

      return redirect()->back()->with('message', "Thanks, your quote request has been sent");

    }

View

I then loop through the values in the passed array and display it to the user.

<article class="col-md-12 text-left services bx1-margin">
                

                
                <ul>
                @foreach ($services as $servicesid => $service)
                  <li>
                     --}}
                    <input id="" value="" name="service[]" type="checkbox" class="custom-control-input form-check-input">
                    <span class="custom-control-description"></span>
                    " name="services" type="checkbox" class="custom-control-input form-check-input"> --}}


                  </li>
                @endforeach
                </ul>
              </article>

When the user submits the form, how do I go about receiving the checked checkboxes?

Research

I saw this post here:How to get the values for a series of checkboxes in Laravel 4 controller (if checked) I saw a post her (stackoverflow) and it explains a setting the value to array[], I'm just not quite sure about implementation.




I hava a file with variables and can select with checkbox. How can I write out the result?

For example the file (xml):

<colors>
    <blue>false</blue>
    <red>true</red>
    <orange>true</orange>
    <green>false</green>
</colors>

This belongs to one item. The items stored in arraylist.

I have four checkboxs: blue, red, orange, green.

If i select some of this, show only those items whom has not the selected color.

For example: - if green and red selected show the items which hasn't got green and red colors. - if orange selected show the items which hasn't got orange color.




How do i add search filter

i have this search filter: http://ift.tt/2c04e5L Its made with checkboxes,but i want to add there a searchbar too,which will interact with checkboxes,but dont know how to do it.Can someone help me with jquery or js code,beforehand thanks.

-HTML

<pre id=result> </pre>

<div class="flowers-wrap">

  <h3 style="font-size:14px; font-weight:normal;">Available Flowers</h3>
  <p style="font-size:12px;"><strong>Filter flowers by colour:</strong></p>
  <form>
    <label style="font-size:12px;">
      <input type="checkbox" name="fl-colour" value="red" id="red" /> Red</label>
    <br>
    <label style="font-size:12px;">
      <input type="checkbox" name="fl-colour" value="yellow" id="yellow" /> Yellow</label>
    <br>
    <label style="font-size:12px;">
      <input type="checkbox" name="fl-colour" value="pink" id="pink" /> Pink</label>
    <br>
    <label style="font-size:12px;">
      <input type="checkbox" name="fl-colour" value="purple" id="purple" /> Purple</label>
    <br>
    <label style="font-size:12px;">
      <input type="checkbox" name="fl-colour" value="green" id="green" /> Green</label>
    <br>
    <label style="font-size:12px;">
      <input type="checkbox" name="fl-colour" value="other" id="other" /> Other</label>
  </form>
  <p style="font-size:12px;"><strong>Filter flowers by size:</strong></p>
  <form>
    <label style="font-size:12px;">
      <input type="checkbox" name="fl-size" value="tiny" id="tiny" /> Tiny</label>
    <br>
    <label style="font-size:12px;">
      <input type="checkbox" name="fl-size" value="small" id="small" /> Small</label>
    <br>
    <label style="font-size:12px;">
      <input type="checkbox" name="fl-size" value="medium" id="medium" /> Medium</label>
    <br>
    <label style="font-size:12px;">
      <input type="checkbox" name="fl-size" value="large" id="large" /> Large</label>
    <br>
    <label style="font-size:12px;">
      <input type="checkbox" name="fl-size" value="giant" id="giant" /> Giant</label>
  </form>

</div>

<div class="continents-wrap">

  <h3 style="font-size:14px; font-weight:normal;">Available Continents</h3>

  <div class="continents" style="font-size:12px;">
    <div>Africa
      <input type="checkbox" name="fl-cont" value="africa" id="africa" />
    </div>
    <div>Europe
      <input type="checkbox" name="fl-cont" value="europe" id="europe" />
    </div>
    <div>Asia
      <input type="checkbox" name="fl-cont" value="asia" id="asia" />
    </div>
    <div>North America
      <input type="checkbox" name="fl-cont" value="north-america" id="north-america" />
    </div>
    <div>South America
      <input type="checkbox" name="fl-cont" value="south-america" id="south-america" />
    </div>
    <div>Antarctica
      <input type="checkbox" name="fl-cont" value="antarctica" id="antarctica" />
    </div>
    <div>Australasia
      <input type="checkbox" name="fl-cont" value="australasia" id="australasia" />
    </div>
  </div>

</div>

<div class="flowers">
  <div class="flower" data-id="aloe" data-category="green small medium africa">Aloe</div>
  <div class="flower" data-id="lavendar" data-category="purple green medium africa europe">Lavender</div>
  <div class="flower" data-id="stinging-nettle" data-category="green large africa europe asia">Stinging Nettle</div>
  <div class="flower" data-id="gorse" data-category="green yellow large europe">Gorse</div>
  <div class="flower" data-id="hemp" data-category="green large asia">Hemp</div>
  <div class="flower" data-id="titan-arum" data-category="purple other giant asia">Titan Arum</div>
  <div class="flower" data-id="golden-wattle" data-category="green yellow large australasia">Golden Wattle</div>
  <div class="flower" data-id="purple-prairie-clover" data-category="purple green other medium north-america">Purple Prairie Clover</div>
  <div class="flower" data-id="camellia" data-category="pink other large north-america">Camellia</div>
  <div class="flower" data-id="scarlet-carnation" data-category="red medium north-america">Scarlet Carnation</div>
  <div class="flower" data-id="indian-paintbrush" data-category="red medium north-america">Indian Paintbrush</div>
  <div class="flower" data-id="moss-verbena" data-category="purple other small south-america">Moss Verbena</div>
  <div class="flower" data-id="climbing-dayflower" data-category="blue tiny south-america">Climbing Dayflower</div>
  <div class="flower" data-id="antarctic-pearlwort" data-category="green yellow large antarctica">Antarctic Pearlwort</div>
</div>

-CSS

body {
  font-family: 'Arial';
  color: #646464;
}

.continents-wrap {
  float: left;
  width: 20%;
  margin: 0 5% 0 0;
  padding: 0;
}

.flowers-wrap {
  float: left;
  width: 20%;
  margin: 0 5% 0 0;
  padding: 0;
  position: relative;
}

.flowers {
  float: left;
  width: 50%;
}

.flowers div {
  float: left;
  width: 90%;
  height: 68px;
  line-height: 68px;
  padding: 0 5%;
  background: #eee;
  margin: 0 0 1px;
  position: relative;
}


-JS

var $filterCheckboxes = $('input[type="checkbox"]');

$filterCheckboxes.on('change', function() {

  var selectedFilters = {};

  $filterCheckboxes.filter(':checked').each(function() {

    if (!selectedFilters.hasOwnProperty(this.name)) {
      selectedFilters[this.name] = [];
    }

    selectedFilters[this.name].push(this.value);

  });

  // create a collection containing all of the filterable elements
  var $filteredResults = $('.flower');

  // loop over the selected filter name -> (array) values pairs
  $.each(selectedFilters, function(name, filterValues) {

    // filter each .flower element
    $filteredResults = $filteredResults.filter(function() {

      var matched = false,
        currentFilterValues = $(this).data('category').split(' ');

      // loop over each category value in the current .flower's data-category
      $.each(currentFilterValues, function(_, currentFilterValue) {

        // if the current category exists in the selected filters array
        // set matched to true, and stop looping. as we're ORing in each
        // set of filters, we only need to match once

        if ($.inArray(currentFilterValue, filterValues) != -1) {
          matched = true;
          return false;
        }
      });

      // if matched is true the current .flower element is returned
      return matched;

    });
  });

  $('.flower').hide().filter($filteredResults).show();



});




Checkbox on touchscreen | Using icheck library

I am building a kiosk application and using the icheck libray to style checkboxes.

I am coding the checkbox this way:

<input type="checkbox" name="test" id="test1" value="10">

It works perfectly fine when I use the application on a normal browser with a mouse, however when I test it on the kiosk with a touch screen, for the checkbox to tick and untick itself, it is not working correctly.

If you click directly on it, it doesn't work, however slightly lower or on the right it does.

Any ideas ?




How to change the text size of a checkbox

I want to change the text size of a checkbox in a fragment. The text size itself became bigger, but the little field of the checkbox is now a little bit higher than the text. I hope someone can help me with this. Thanks

This is my code for the CheckBox:

<CheckBox
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="30dp"
        android:text="Text"
        android:paddingTop="@dimen/my_padding"
        android:id="@+id/text" />




WPF grouping for checkboxes

    <CheckBox Content="1" Margin="43,73,430,227" />
    <CheckBox  Content="2" Margin="123,73,359,227"/>
</Grid>

Above are my checkboxe. I need to group them. I f check 1 then 2 should be unchecked and vice versa. This should be done in xaml. Is there any property settings or xaml code to apply my requirement other than adding c# code.




How to print the checked values of checkbox to print document in c# windows form application

I wants to show contents of form using printPreview dialog. All is fine but checkbox is making problem. The selected values of checkbox are not shown and I don't know how to do it.




mardi 27 décembre 2016

check/uncheck the check box only if the confirmation message is true in angular js

I am new in angular js. I have a check box when i click on that checkbox a confirmation message will appear. I need to to check or uncheck the check box only if i confirm the confirmation message. How can i do it with angular js.(currently the check box is check/uncheck even if i cancel the confirmation message). This is my check box element.

<input type="checkbox" ng-init="checkValue = x.status" ng-model="checkValue" ng-true-value="1" ng-false-value="0" ng-checked="x.status == 1" ng-click="changeStatus(<% x.id %>, 1, checkValue)">

And this is my js part

var confrm          = confirm('Are you sure that you want to do this');
    if (confrm) {
        Data.post('url', param)
        .then(function(data){
            if (data.success == 1)
                AlertService.setSuccess('Status changed successfully!');
            else 
                AlertService.setError('Some error occured. Please try again');
        })
    }




can I use the same checkbox in two forms ? C# Visualstudio

ello.. I'm making a basic program that shows factorial numbers..

I've made two forms(Form1,Form2), with a checkbox for music in each form, the problem is when I click it in form1 and form2 its overlap (two same music running at the same time..)

is there is a way share the same checkbox in two forms?

-Thanks : )




How do I use if statements with checkboxes without clutter

I have this application with 13 checkboxes.
And i want to do if statements to check if a textbox is checked but its going to get really cluttered after checking 4 of them for example

if (checkBox1.IsChecked == true)
    {
          DoSomething();          
    }

else if (checkBox1.IsChecked == true && checkBox2.isChecked = false)
    {
          DoSomething();          
    }

else if (checkBox1.IsChecked == false && checkBox2.isChecked = true)
    {
          DoSomething();          
    }

else if (checkBox1.IsChecked == false && checkBox3.isChecked = true)
    {
          DoSomething();          
    }

else if (checkBox1.IsChecked == false && checkBox3.isChecked = false)
    {
          DoSomething();          
    }


else if (checkBox1.IsChecked == true && checkBox3.isChecked = false)
    {
          DoSomething();          
    }

else if (checkBox1.IsChecked == true && checkBox3.isChecked = true)
    {
          DoSomething();          
    }

I bet you can see the pattern already.. I need to check every possible solution for 13 checkboxes, is there a way to do this more efficiently?




Expandable ListView checkbox child checkChangeListener?

I want when I checked the each child checkboxes start the diffrent method in DatabaseHelper. There is MainActivity:

public class MainActivity extends AppCompatActivity {
ExpListViewAdapterWithCheckbox listAdapter;
ExpandableListView expListView;
ArrayList<String> listDataHeader;
HashMap<String, List<String>> listDataChild;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    expListView = (ExpandableListView) findViewById(R.id.lvExp);
    prepareListData();
    listAdapter = new ExpListViewAdapterWithCheckbox(this, listDataHeader, listDataChild);
    expListView.setAdapter(listAdapter);
    expListView.setOnGroupClickListener(new OnGroupClickListener() {

        @Override
        public boolean onGroupClick(ExpandableListView parent, View v,
                                    int groupPosition, long id) {
            return false;
        }
    });
    expListView.setOnGroupExpandListener(new OnGroupExpandListener() {

        @Override
        public void onGroupExpand(int groupPosition) {
            Toast.makeText(getApplicationContext(),
                    listDataHeader.get(groupPosition) + " Expanded",
                    Toast.LENGTH_SHORT).show();
        }
    });

    // Listview Group collasped listener
    expListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {

        @Override
        public void onGroupCollapse(int groupPosition) {
            Toast.makeText(getApplicationContext(),
                    listDataHeader.get(groupPosition) + " Collapsed",
                    Toast.LENGTH_SHORT).show();

        }
    });

    // Listview on child click listener
    expListView.setOnChildClickListener(new OnChildClickListener() {

        @Override
        public boolean onChildClick(ExpandableListView parent, View v,
                                    int groupPosition, int childPosition, long id) {

            if(groupPosition == 1 && childPosition == 1) {

            DatabaseHelper db = new DatabaseHelper(MainActivity.this);
            db.arpa();


            }
ifif(groupPosition == 1 && childPosition == 2) {

            DatabaseHelper db = new DatabaseHelper(MainActivity.this);
            db.bugday();


            }

            return true;
        }
    });

    Button button = (Button) findViewById(R.id.button);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            Intent i = new Intent(MainActivity.this , TumKayitlar.class);
            startActivity(i);

        }
    });

}


private void prepareListData() {
    listDataHeader = new ArrayList<String>();
    listDataChild = new HashMap<String, List<String>>();

    // Adding child data
    listDataHeader.add("Tahıl Ürünleri");
    listDataHeader.add("Baklagiller");
    listDataHeader.add("Sebzeler");

    // Adding child data
    List<String> tahilürünleri = new ArrayList<String>();
    tahilürünleri.add("Arpa");
    tahilürünleri.add("Buğday");
    tahilürünleri.add("Mısır");
    tahilürünleri.add("Darı");

    List<String> baklagiller = new ArrayList<String>();
    baklagiller.add("Nohut");
    baklagiller.add("Fasulye ");
    baklagiller.add("Bezelye");
    baklagiller.add("Mısır");


    List<String> sebzeler = new ArrayList<String>();
    sebzeler.add("Pırasa");
    sebzeler.add("Ispanak");
    sebzeler.add("Patlıcan");
    sebzeler.add("Domates");
    sebzeler.add("Patates");

    listDataChild.put(listDataHeader.get(0), tahilürünleri);
    listDataChild.put(listDataHeader.get(1), baklagiller);
    listDataChild.put(listDataHeader.get(2), sebzeler);
}

For example when I checked the Cbx "Arpa" I want start db.arpa(); or I checked the "Buğday" start db.bugday();

There is Databasehelper part:

 public void nohut() {

    nohutt = true;

}
public bugday() {
bugday = true;
}

Displaying DB codes:

public class TumKayitlar extends Activity{


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.expandable_listview);
    DatabaseHelper dbHelper = new DatabaseHelper(this);
    SQLiteDatabase db = dbHelper.getReadableDatabase();
    String[] getColumnName = {"_id,  student_name , student_surname "};
    Cursor imlec = db.query(" student ",getColumnName, "student_surname = 81 " , null, null,null,null);
    ListView listView = (ListView) findViewById(R.id.lvExp2);
    ArrayList<String> student = new ArrayList<String >();
    ArrayAdapter<String > adapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,student);
    int student_name = imlec.getColumnIndex(" student_name ");
    int student_surname = imlec.getColumnIndex(" student_surname ");
    int _id = imlec.getColumnIndex("_id");
    String name_surname = student_name + "  " + student_surname;
    while (imlec.moveToNext()){
        name_surname =   imlec.getString(1) + "  " + imlec.getString(2) + "\n";
        student.add(name_surname);
    }
    listView.setAdapter(adapter);
    imlec.close();
    db.close();
}

}

And by the way ExpandableAdapter:

  public class ExpListViewAdapterWithCheckbox extends BaseExpandableListAdapter {
    private Context mContext;
    private HashMap<String, List<String>> mListDataChild;
    private ArrayList<String> mListDataGroup;
    private HashMap<Integer, boolean[]> mChildCheckStates;
    private evdenevarcom.ar.evdenevar.MainActivity.ExpListViewAdapterWithCheckbox.ChildViewHolder childViewHolder;
    private evdenevarcom.ar.evdenevar.MainActivity.ExpListViewAdapterWithCheckbox.GroupViewHolder groupViewHolder;
    private String groupText;
    private String childText;
    public ExpListViewAdapterWithCheckbox(Context context, ArrayList<String> listDataGroup,          HashMap<String, List<String>> listDataChild){
        mContext = context;
        mListDataGroup = listDataGroup;
        mListDataChild = listDataChild;
        mChildCheckStates = new HashMap<Integer, boolean[]>();
    }

    public int getNumberOfCheckedItemsInGroup(int mGroupPosition)
    {
        boolean getChecked[] = mChildCheckStates.get(mGroupPosition);
        int count = 0;
        if(getChecked != null) {
            for (int j = 0; j < getChecked.length; ++j) {
                if (getChecked[j] == true) count++;
            }
        }
        return  count;
    }

    @Override
    public int getGroupCount() {
        return mListDataGroup.size();
    }
    @Override
    public String getGroup(int groupPosition) {
        return mListDataGroup.get(groupPosition);
    }
    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }
    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
                             View convertView, ViewGroup parent) {
        groupText = getGroup(groupPosition);
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) mContext
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.list_group, null);
            groupViewHolder = new evdenevarcom.ar.evdenevar.MainActivity.ExpListViewAdapterWithCheckbox.GroupViewHolder();
            groupViewHolder.mGroupText = (TextView) convertView.findViewById(R.id.lblListHeader);
            convertView.setTag(groupViewHolder);
        } else {

            groupViewHolder = (evdenevarcom.ar.evdenevar.MainActivity.ExpListViewAdapterWithCheckbox.GroupViewHolder) convertView.getTag();
        }
        groupViewHolder.mGroupText.setText(groupText);
        return convertView;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return mListDataChild.get(mListDataGroup.get(groupPosition)).size();
    }
    @Override
    public String getChild(int groupPosition, int childPosition) {
        return mListDataChild.get(mListDataGroup.get(groupPosition)).get(childPosition);
    }
    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }
    @Override
    public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        final int mGroupPosition = groupPosition;
        final int mChildPosition = childPosition;

        childText = getChild(mGroupPosition, mChildPosition);
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) this.mContext
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.list_item, null);
            childViewHolder = new evdenevarcom.ar.evdenevar.MainActivity.ExpListViewAdapterWithCheckbox.ChildViewHolder();
            childViewHolder.mChildText = (TextView) convertView
                    .findViewById(R.id.lblListItem);
            childViewHolder.mCheckBox = (CheckBox) convertView
                    .findViewById(R.id.lstcheckBox);
            convertView.setTag(R.layout.list_item, childViewHolder);
        } else {

            childViewHolder = (evdenevarcom.ar.evdenevar.MainActivity.ExpListViewAdapterWithCheckbox.ChildViewHolder) convertView
                    .getTag(R.layout.list_item);
        }
        childViewHolder.mChildText.setText(childText);


        childViewHolder.mCheckBox.setOnCheckedChangeListener(null);
        if (mChildCheckStates.containsKey(mGroupPosition)) {
            boolean getChecked[] = mChildCheckStates.get(mGroupPosition);
            childViewHolder.mCheckBox.setChecked(getChecked[mChildPosition]);

        } else {
            boolean getChecked[] = new boolean[getChildrenCount(mGroupPosition)];
            mChildCheckStates.put(mGroupPosition, getChecked);
            childViewHolder.mCheckBox.setChecked(false);
        }
        childViewHolder.mCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {

                    boolean getChecked[] = mChildCheckStates.get(mGroupPosition);
                    getChecked[mChildPosition] = isChecked;
                    mChildCheckStates.put(mGroupPosition, getChecked);

                } else {
                    boolean getChecked[] = mChildCheckStates.get(mGroupPosition);
                    getChecked[mChildPosition] = isChecked;
                    mChildCheckStates.put(mGroupPosition, getChecked);
                }

            }
        });
        return convertView;

    }
    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return false;
    }
    @Override
    public boolean hasStableIds() {
        return false;
    }
    public final class GroupViewHolder {
        TextView mGroupText;
    }
    public final class ChildViewHolder {

        TextView mChildText;
        CheckBox mCheckBox;
    }
}
}

Please help me I'm almost nothing know about java. :((




Excel VBA - Verify if the checkboxes are selected and concatenate respective textboxes's values

I am a beginner in Excel VBA and would like some help, please.

In a customer registration userform I have a "contacts" section, which will be reserved to receive up to 5 contact emails for the customer that is being registered. In this userform I have the following objects:

  • 5 text boxes (txtEmail1, txtEmail2, txtEmail3, ...)
  • 5 checkboxes (ckboxEmail1, ckboxEmail2, ckboxEmail3, ...)
  • 1 commandbutton (bSendEmail)

The emails will be typed in the text boxes and the button will be used to open Outlook Application with the emails already in the "To" field. The checkboxes will be used to define which emails will be included in the "To" field.

Here comes my doubt. How can I verify which checkboxes are checked, to use (concatenate) only their emails from text boxes?

Practical Example 1:

TxtEmail1.value = email1@example.com
TxtEmail2.value = email2@example.com
TxtEmail3.value = empty
TxtEMail4.value = email4@example.com
TxtEMail5.value = empty

CkboxEmail1.value = true
CkboxEmail2.value = true
CkboxEmail3.value = false
CkboxEmail4.value = true
CkboxEmail5.value = false

When I do press the button, the following array must be passed to the ".To" property:

.To = "email1@example.com;email2@example.com;email4@example.com"

Practical example 2:

TxtEmail1.value = email1@example.com
TxtEmail2.value = email2@example.com
TxtEmail3.value = empty
TxtEMail4.value = email4@example.com
TxtEMail5.value = empty

CkboxEmail1.value = false
CkboxEmail2.value = false
CkboxEmail3.value = false
CkboxEmail4.value = true
CkboxEmail5.value = false

When I do press the button, only the 4th email will be passed to the ".To" property, because only its checkbox is true:

.To = "email4@example.com"

Bellow is the code I'm using to open Outlook Application in the bSendEmail Click event.

Private Sub bSendEmail_Click()

Dim outlookApp       As Object
Dim outlookMail      As Object

On Error GoTo error_outlook
Set outlookApp = CreateObject("Outlook.Application")
Set outlookMail = outlookApp.CreateItem(0)
On Error GoTo 0

On Error Resume Next
With outlookMail
    .To = ""
    .CC = ""
    .BCC = ""
    .Subject = ""
    .Body = ""
    .Importance = 2
    .Display
End With
On Error GoTo 0

Set outlookMail = Nothing
Set outlookApp = Nothing

Exit Sub

error_outlook:

    MsgBox("some message here...", vbOKOnly + vbExclamation, "ERROR - Outlook")
    Exit Sub

End Sub

Thanks in advance and sorry about the bad English, is not my native language.




ionic2 how to get checkbox status

here is the context:

I have a list of users.

I also have a list of items and each item holds an Array of users.

The items list is displayed like that:

  <ion-list>
    <ion-item *ngFor="let item of items">
      <ion-checkbox item-left [checked]="isChecked(item)" *ngIf="selected_user;"></ion-checkbox>
      <ion-label>
        
        <br>
        <ion-badge *ngFor="let user of item.users"></ion-badge>
      </ion-label>
    </ion-item>
  </ion-list>

Basically the checkboxes are revealed when a user is selected somewhere else.

What I am trying to do is to modify for each item its users array according to the status of the checkbox.

For instance, if item_a.users contain user1 and selected_user is user1 its checkbox revealed as checked (I have that already) but now if item_b and item_c will be checked I want to add user1 to their users array and if item_a is unchecked I want to remove user1 from its users array.

Is there any event to catch here? Is there a way to get all the status together in some data structure or I have to handle it individually for each item?

Thanks.




How to enabled/disabled submit button based on checkboxes?

I want to enable submit button when one or more checkbox value is selected , i tried with below code its enabling button but if i check one value its making all checkbox seletced ? Any idea what is implemented wrong ?

main.html

<tr ng-repeat="user in userList track by $index">
          <td st-ratio="20"></td>
          <td st-ratio="30"> </td>
          <td st-ratio="20"><input type="checkbox" ng-model="userList.selected" ng-click="checkedValue(user)"> </td>
        </tr>

 <button class="btn btn-primary" ng-disabled="user.selected" ng-disabled="!userList.selected" ng-click="addUsers()">Add User(s)</button>

Ctrl.js

$scope.$on('show-user-list',function(e,data){
    $scope.userList = data;
    $scope.userList.selected = false;
  });


 $scope.checkedValue = function(user) {
 user._id = user.attuid;
 user.type = 'user';
        if ($scope.selectedUsers.indexOf(user) === -1) {
            $scope.selectedUsers.push(user);
            $scope.userList.selected = true;
        } else {
            $scope.selectedUsers.splice($scope.selectedUsers.indexOf(user), 1);
        }
        console.log($scope.userList.selected);
    };




Check a checkbox in an HTML page with Python 3.5 & Selenium

I am trying to select all checkboxes that appear on an HTML page with Python 3.5 and Selenium. The final goal is obviously to manipulate them, but I can't even manage to select them properly.

I can't just give you the exact URL, because it's a special page on eBay and you need to be connected to see it. So, here's how to access the web page that interest me:

  1. Go to http://ift.tt/2hZWqXk
  2. Create an account or Log In
  3. Go to http://ift.tt/2i4an6y when connected
  4. Type in "iPhone" or any brand you want, it doesn't matter, and click on the "Start selling" button.
  5. You are on the page.

You can see that, if you type 'iPhone', eBay proposes you to choose from one of all of these categories:

Mobile Phones & Communication

Mobile & Smart Phones

Mobile Phone & PDA Accessories > Other Mobile Phone Accessories

Other Phones

Smart Watches

Mobile Phone & PDA Accessories > Cables & Adapters

Mobile Phone Parts

Mobile Phone & PDA Accessories > Chargers & Docks

Mobile Phone & PDA Accessories > Headsets

Mobile Phone & PDA Accessories > Cases & Covers

Wholesale & Job Lots

Other Wholesale & Job Lots

My goal is to tick the first checkbox, no matter how much checkboxes there are on the page. I just want to check the very first one. It's simple as that. In this example, that means check the checkbox "Mobile & Smart Phones".

I tried the XPATH method:

checkBox = driver.find_elements_by_xpath(".//input[@type='checkbox']")

But when I try print(checkBox), it returns [ ] (=nothing). It's strange because in Firefox this XPATH give me just exactly what I need.

I also tried to select it with the class name:

checkBox = driver.find_elements_by_class_name('inpChkBox')

But again, it results in nothing when I try to print it.

How can I just generate a list of all the checkboxes on the page, in order to manipulate them after?

It seems like the id, name, etc of all checkboxes are unique and generated automatically, so I can't just select them by their ID, or Value, or Name. I need something that detects all checkboxes in the page and put them in a list.

Thanks for any help




Select all checkboxes on HTML page with Python 3.5 & Selenium

I am trying to select all checkboxes that appear on an HTML page. The final goal is obviously to click on some of them, but I can't even manage to select them properly.

Here's the HTML:

<div class="idtTopSm">
<table cellpadding="0" cellspacing="0" border="0" summary="">
<tbody>
<tr>
<td valign="top">
<div id="leaf_53557_inp">
<table cellpadding="0" cellspacing="0" border="0" summary="">
<tbody>
<tr>
<td valign="top">
<div id="leaf_53557_ctr_1" class="inpChkBox">
<input type="checkbox" id="leaf_53557" name="leaf_53557" value="53557" title="Womens Shoes > Boots">
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
<td valign="top">
<span id="leaf_text_53557">Womens Shoes &gt; Boots</span>
</td>
</tr>
<tr>
<td valign="top">
<div id="leaf_57974_inp">
<table cellpadding="0" cellspacing="0" border="0" summary="">
<tbody>
<tr>
<td valign="top">
<div id="leaf_57974_ctr_1" class="inpChkBox">
<input type="checkbox" id="leaf_57974" name="leaf_57974" value="57974"     title="Kids Clothes, Shoes &amp; Accs. > Girls Shoes">
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
<td valign="top">
<span id="leaf_text_57974">Kids Clothes, Shoes &amp; Accs. &gt; Girls             Shoes</span>
</td>
</tr>
</tbody>
</table>
</div>

So in order to select ALL checkboxes (there are 2 here, Women's Shoes > Boots & Kids' Clothes, and Shoes & Accs. > Girls' Shoes) I tried different things, but nothing worked.

I tried the XPATH method:

checkBox = driver.find_elements_by_xpath(".//input[@type='checkbox']")

But when I try to print(checkBox), it returns [ ] (=nothing). It's strange because in Firefox this XPATH give me just exactly what I need.

I also tried to select it with the class name:

checkBox = driver.find_elements_by_class_name('inpChkBox')

But again, it results in nothing when I try to print it.

How can I just generate a list of all the checkboxes on the page, in order to manipulate them after?

It seems like the id, name, etc of all checkboxes are unique and generated automatically, so I can't just select them by their ID, or Value, or Name. I need something that detects all checkboxes in the page and put them in a list.

Thanks for any help




Styling a checkbox

How can I style a checkbox to appear as shown in the image below

enter image description here

It can be great if I can use the label element inside the checkbox. Thanks for your tips.




Checking all checkboxes with Selenium

I am trying to check all checkboxes on a page similarily to http://ift.tt/2htoZ09.

I try to do this with

checkboxes = driver.find_elements_by_class_name('gwt-CheckBox')
for checkbox in checkboxes:
    if not checkbox.is_selected():
        checkbox.click()

however, all checkboxes give False for is_selected() so the ones that are already selected get switched off and the ones that are not selected get switched on. Below I have an example of the a checked CheckBox class (Library Name) and an unchecked Checkbox class (Paired nominal length).

How can I check if these are already selected?

  <div style="position: relative; display: inline-block; vertical-align: top; float: left;">
   <span class="gwt-CheckBox">
    <input id="gwt-uid-27" tabindex="0" type="checkbox" value="on"/>
    <label for="gwt-uid-27">
     Library name
    </label>
   </span>
  </div>
 </div>
 <div class="holderFp" style="width: 100%; position: relative; overflow: hidden; display: block;">
  <div style="position: relative; display: inline-block; vertical-align: top; float: left; width: 25%;">
   <span class="gwt-CheckBox">
    <input id="gwt-uid-28" tabindex="0" type="checkbox" value="on"/>
    <label for="gwt-uid-28">
     Paired nominal length
    </label>
   </span>
  </div>




Checkbox IOS swift


I'am going to work for a project that it will be a lot of checkbox, i found a solution like under but i know this not right why.

 @IBAction func btn_box(sender: UIButton) {
    if (btn_box.selected == true)
    {
        btn_box.setBackgroundImage(UIImage(named: "box"), forState: UIControlState.Normal)

            btn_box.selected = false;
    }
    else
    {
        btn_box.setBackgroundImage(UIImage(named: "checkBox"), forState: UIControlState.Normal)

        btn_box.selected = true;
    }
}

so anyone can suppose to me the best why i have more then 20 checkbox in this projet.

Thanks,




Select and deselect all check-boxes on click in AngularJs

I am having difficulties in understanding how to find out if some checkbox is selected or not in Angular.

This is the problem:

I have simple HTML table, on ng-change event I am calling one function that need to check if 'select all' checkbox is checked:

This is HTML:

<table class="table table-striped">
    <thead>
        <tr class="table-header">
            <th ng-if="!newTestSessionCtrl.formData.battery.id"><input type="checkbox" ng-model="selectedAll" ng-change="newTestSessionCtrl.isSelectAll()" /></th>
            <th>Test</th>
            <th>Available Time</th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="row in newTestSessionCtrl.formData.battery.testDefinitions">
            <td ng-if="!newTestSessionCtrl.formData.battery.id"><input type="checkbox" ng-model="row.selected" ng-change="newTestSessionCtrl.isLabelChecked(); newTestSessionCtrl.validate()" /></td>
            <td></td>
            <td> minutes</td>
        </tr>
    </tbody>
</table>

The name of model is: selectedAll

I have two functions, first one should be use for select all and deselect:

isSelectAll() {
    let self = this;
    self.model.selectedLabelList = [];
    if(self.selectedAll) {
        self.selectedAll = true;
        for(var i=0; i < self.formData.battery.testDefinitions.length; i++) {
            self.model.selectedLabelList.push(self.formData.battery.testDefinitions[i].name);       
        }
    }
    else { 
        self.selectedAll = false; 
    }
    angular.forEach(self.formData.battery.testDefinitions, function(item) {
        item.selected = self.selectedAll;
    });
}

And the other one for un-checking 'select all' checkbox if one of the check boxes is deselected manual are this:

isLabelChecked() {
    let self = this;
    let _name = this.formData.battery.name;
    if(this.formData.battery.selected) {
        self.model.selectedLabelList.push(_name);
        if(self.model.selectedLabelList.length == self.labelList.length ) {
            self.selectedAll = true;
        }
    }else{
        self.selectedAll = false;
        let index = self.model.selectedLabelList.indexOf(_name);
        self.model.selectedLabelList.splice(index, 1);
    }
}  

The problem is when defining selectedAll in js file.

I have constructor and if I do not define anything in it, selectedAll won't be in scope.

If I do this:

class NewTestSessionController {
    constructor($scope, $state, resources, NewTestSessionService, formats, AuthenticationService, toastr, momentTimezone, _) {
        this.model = {
            selectedLabelList : []
        };

        this.selectedAll;
}

selectedAll will be in scope, but I will get 'false' value always. No matter if I have selected or deselected checkbox. If I assign some value like this this.selectedAll = true it won't be working correctly of course.

I have problem understanding why ng-model="selectedAll" is not visible and how can I make it visible in js file, without using $scope, since the main goal of my practice is to avoid usage of it.

Can someone see where I am making a mistake?