vendredi 27 mars 2015

Javascript check/uncheck all checkboxes and write values to textarea

This is my first js script so be gentle with me :)


The problem is when I click on check all button, all checkboxes are checked but it won't write values to textarea, if I click individual checkboxes then the value is added/removed and that is ok, I'm just stuck on that check all/uncheck all button.


http://ift.tt/1HT4uQr





function check(chk) {
for (i = 0; i < chk.length; i++)
chk[i].checked = true ;
}

function uncheck(chk) {
for (i = 0; i < chk.length; i++)
chk[i].checked = false ;
}

var itemsAdded = Array();

function movetext(text) {
var i = itemsAdded.indexOf(text)
if ( i >= 0) {
itemsAdded.splice(i,1);
}
else {
itemsAdded.push(text);
}
document.getElementById("result").value=itemsAdded.join("\n");
}



<form>
<input type='checkbox' value='aaa' name="add" onclick='movetext(this.value)'/>a
<input type='checkbox' value='bbb' name="add" onclick='movetext(this.value)'/>b
<input type='checkbox' value='ccc' name="add" onclick='movetext(this.value)'/>c
<input type='checkbox' value='ddd' name="add" onclick='movetext(this.value)'/>d
<input type='checkbox' value='eee' name="add" onclick='movetext(this.value)'/>e

<input type="button" value="check all" onClick="check(this.form.add)">
<input type="button" value="uncheck all" onClick="uncheck(this.form.add)">

<br>

<textarea id="result" rows="8" cols="40"></textarea>






jQuery toggle multiple checkboxes with one button

i am trying to code an easy way to check and uncheck form checkboxes with jQuery. I have tried some of the examples found in stackoverflow, but my limited JS knowledge is keeping me from getting results.


Here is my code, and it is not changing the input checkboxes to "checked" as i intended, i also included a button to clear the selection, but JS still does not reference it.


HTML



<section id="opzioni">

<div class="bottoni-toggle">
<!-- toggle button -->
<input id="#select-all" type="button" value="Tutti" title="Toggle">
<!-- clear button -->
<input id="#select-none" type="button" value="Nessuno" title="Clear">
</div>

<div class="col_opt">
<span class="custom_chb_wrapper">
<span class="custom_chb">
<input class="bottone-opzioni" id="_4wd" name="_4wd" type="checkbox">
<input id="_4wd" name="_4wd" type="hidden" value="0">
</span>
<label>4WD</label>
</span>
</div>

<div class="col_opt">
<span class="custom_chb_wrapper">
<span class="custom_chb">
<input class="bottone-opzioni" id="_airbag" name="_airbag" type="checkbox">
<input id="_airbag" name="_airbag" type="hidden" value="0">
</span>
<label>Airbag</label>
</span>
</div>


jQuery



$(document).ready(function() {
$("#select-all").click(function() {
var checkBoxes = $("input.bottone-opzioni");
checkBoxes.prop("checked", !checkBoxes.prop("checked"));
});
});


Here is the fiddle i set up to test: Hope you can help.





checkbox label with div in it on ipad not clickable

i have the following situation:


i have made hidden checkboxes and labels which are clickable.


when testing in browsers all works like a charm, but on ipad the label only take the click, when i am not hitting any text, which is in the label.


why is that so?


here my markup of one box:



<input name="Quantify-Studienzusammenfassung" value="no" type="hidden" />
<input class="chk_button" name="Quantify-Studienzusammenfassung" id="chk_quantify_studien" type="checkbox" value="yes" />
<label for="chk_quantify_studien">
<div class="label_div">
<h3>Quantify-Studienzusammenfassung:</h3>
<p>Kurzatmigkeit vs. Tiotropium/Formoterol (in freier Kombination)</p>
</div>
</label>




how can i set checkbox in header template in gridview? inc# side

I want to change the checkbox value in grid view in cs code not in asp.net side? How can i set the it?


I tried it



while (reader.Read())
{
foreach (TableCell headerCell in GridView1.HeaderRow.Cells)
{
// or access Controls with index
// headerCell.Controls[INDEX]
headerCell.FindControl("c") as CheckBox = true;

}
}




Display Selected as well as NOT Selected checkboxes using ACF

I tried to find a related topic on the acf site but that didn't give me the right answer. Hopefully you guys can help me out.


I am building a custom website using ACF, everything is perfect and I managed to get almost everything exactly the way I want but with the checkboxes I can only display the checked ones but not the unchecked.


My idea is that the not checked ones would have a different "class" or "id" and I would display them with a different CSS style.


This is a list of features of the flats for rent, so things like: Internet, TV, etc. Much like airbnb's website.


So the code. I managed to get this code to work:



<?php

$values = get_field('room_features');
if($values)
{
echo '<ul>';

foreach($values as $value)
{
echo '<li>' . $value . '</li>';
}

echo '</ul>';
}

?>


But this doesn't display the unchecked ones, only checked.


I would appretiate any light on this :)





how to generate checkbox from values user can select to values user selected

i've an application where user at first page shown 4 products which he can choose, now after he saves the data, i've to show list of all four products, and have to put check, which were saved by the user, i'm unable to crack the logic, would love if you could help



// user can choose from these products
$products = array('1'=>'Product One','2'=>'Product Two','3'=>'Product Three','4'=>'Product Four');
// user has choosen these products
$selected_products = explode(',', 'Product One,Product Four');
foreach($selected_products as $product)
{
// have to print out all products from $products variable, and check the ones user selected from the $selected_products string in checkbox html input type
}




JavaFX: Add CheckBoxTreeItem in TreeTable?

I am experimenting with JavaFX and I am trying to add a check box Item in tree table, but it looks like it supports only simple tree item.


My Code is modified version of Oracle's TreeTableView Example:



public class TreeTableViewSample extends Application implements Runnable {

List<Employee> employees = Arrays.<Employee>asList(
new Employee("Ethan Williams", 30.0),
new Employee("Emma Jones", 10.0),
new Employee("Michael Brown", 70.0),
new Employee("Anna Black", 50.0),
new Employee("Rodger York", 20.0),
new Employee("Susan Collins", 70.0));

/* private final ImageView depIcon = new ImageView (
new Image(getClass().getResourceAsStream("department.png"))
);
*/
final CheckBoxTreeItem<Employee> root
= new CheckBoxTreeItem<>(new Employee("Sales Department", 0.0));
final CheckBoxTreeItem<Employee> root2
= new CheckBoxTreeItem<>(new Employee("Departments", 0.0));

public static void main(String[] args) {
Application.launch(TreeTableViewSample.class, args);
}

@Override
public void start(Stage stage) {
root.setExpanded(true);
employees.stream().forEach((employee) -> {
root.getChildren().add(new CheckBoxTreeItem<>(employee));
});
stage.setTitle("Tree Table View Sample");
final Scene scene = new Scene(new Group(), 400, 400);
scene.setFill(Color.LIGHTGRAY);
Group sceneRoot = (Group) scene.getRoot();

TreeTableColumn<Employee, String> empColumn
= new TreeTableColumn<>("Employee");
empColumn.setPrefWidth(150);
empColumn.setCellValueFactory(
(TreeTableColumn.CellDataFeatures<Employee, String> param)
-> new ReadOnlyStringWrapper(param.getValue().getValue().getName())
);

TreeTableColumn<Employee, Double> salaryColumn
= new TreeTableColumn<>("Salary");
salaryColumn.setPrefWidth(190);
/* salaryColumn.setCellValueFactory(
(TreeTableColumn.CellDataFeatures<Employee, String> param) ->
new ReadOnlyDoubleWrapper(param.getValue().getValue().getEmail())
);
*/
salaryColumn.setCellFactory(ProgressBarTreeTableCell.<Employee>forTreeTableColumn());
root2.getChildren().add(root);

TreeTableView<Employee> treeTableView = new TreeTableView<>(root2);
treeTableView.getColumns().setAll(empColumn, salaryColumn);
sceneRoot.getChildren().add(treeTableView);
stage.setScene(scene);
stage.show();
ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
executorService.scheduleAtFixedRate(this, 3, 10, TimeUnit.SECONDS);

}

@Override
public void run() {
root2.getValue().setSalary(calcSalary(root));
}

public double calcSalary(TreeItem<Employee> t) {
Double salary = 0.0;
if (!t.isLeaf()) {

ObservableList<TreeItem<Employee>> al = t.getChildren();
for (int i = 0; i < al.size(); i++) {
TreeItem<Employee> get = al.get(i);
salary += calcSalary(get);
}
t.getValue().setSalary(salary);
}
return salary += t.getValue().getSalary();
}

public class Employee {

private SimpleStringProperty name;
private SimpleDoubleProperty salary;

public SimpleStringProperty nameProperty() {
if (name == null) {
name = new SimpleStringProperty(this, "name");
}
return name;
}

public SimpleDoubleProperty salaryProperty() {
if (salary == null) {
salary = new SimpleDoubleProperty(this, "salary");
}
return salary;
}

private Employee(String name, Double salary) {
this.name = new SimpleStringProperty(name);
this.salary = new SimpleDoubleProperty(salary);
}

public String getName() {
return name.get();
}

public void setName(String fName) {
name.set(fName);
}

public Double getSalary() {
return salary.get();
}

public void setSalary(Double fName) {
salary.set(fName);
}
}
}


Is there any way i can use checkboxes for tree item in the above example? I am using JavaFx 8.


I am also try to create Salary Bars, which can also be used as progressbar for a task and its sub tasks. (Just playing with UI). But don't know how to connect them with the real values of employe, as i guess normal table view is different from tree table view. Thanks ! :)