dimanche 29 mars 2015

check all checkboxes javascript

I'm trying to have all checkboxes checked (true) when the user clicks on "All" button. I tried this, firstly just to see if "Anglais" could be checked clicking on "All" :



<input type="checkbox" name="anglais" id="anglais" value="Anglais" /> Anglais
<input type="checkbox" name="allemand" id="allemand" value="Allemand" /> Allemand
<input type="checkbox" name="espagnol" id="espagnol" value="Espagnol" /> Espagnol
<input type="checkbox" name="francais" id="francais" value="Francais" /> Francais
<input type="checkbox" onclick="checkedAll()" name="all" id="all" value="Tous" /> Tous


My Javascript :



function checkedAll () {
var checked = false;
var all = document.getElementById('all');
if (checked == false) {
checked = true
}
else {
checked = false
}
var ang = document.getElementById('anglais').checked
if (ang == true) {
ang.checked = true;
}


But the button(s) are not checked when I click on All. I think I don't understand exactly how to use the .checked method..

Maybe, some of my code has not logic, because it was from this example : http://ift.tt/1CnsBCe





Ember js checkbox value

I'm new to Ember and this drives me crazy. I've read checkbox documentation several times but I still don't understand. I have form for adding employees and need to be able to choose employee's education level. I know that should be the select box but task says checkboxes. So, I have few checkboxes and I should be able to pass values from checked ones to action handler and to save them but i don't know how to assign value to checkbox(from docs I got that i should use checked instead value but don't know how).


Thanks in advance and sorry for noob question





How to build a TinyDB with values from CheckBox and TextBox in App Inventor2?

I'm trying my best to learn App Inventor2. Although I'm a little familiar with coding in Java with Eclipse and Android Studio and I'm aware of App Inventor limitations, I like most, the graphical interface and the visual objects, than developing an app all the way in code.


I'm having a screen in an app as the following image, that I need to achieve this functionality: a. User checks a "CheckBox" related to an image of their liking. b. User inputs some identification related (id1, id2) to this image. c. Clicks the "Save" button to store this values (checkBox, id1,id2) to a TinyDB. d. Clicks the "Reset" button to clear info stored in TinyDB (checkBox, id1,id2).


enter image description here


I know that TinyDB can only store text. I have tried to make a TinyDB with a tag as a list named "idList" and have it populated with the values from "checkBox", "id1","id2", without success. I believe that I'm knot checking weather the "checkBox" changed or something like that.


Can someone be kind enough to point me to the right direction following this logic, or point me to something better if I'm wrong?


Thank you all in advance for your answers.





Check current and previous checkboxes

I am quite new to jquery and javascript to be honest and I am having trouble with checkboxes.


This works as #checkAll is a checkbox used for checking all the other checkboxes with class "check":



function test() {
if($("#checkAll").prop('checked')) {
$(".check").prop('checked', true);
} else {
$(".check").prop('checked', false);
}
}


However, I want it to work when I select any checkbox. So I tried putting the function to all checkboxes as a click event, just using onclick="test()".


I think the problem is that I am trying to use $(this) but I must be using it wrongly, what I have is:



function test() {
if($(this).prop("checked")) {
$(".check").prop("checked", true);
} else {
$(".check").prop("checked", false);
}
}


"$(this)" also has the class "check", so maybe it's to do with that.


Ultimately I want to check one box and it check all previous checkboxes, not ones that come afterwards. I think if I get my head around why this isn't working then I should be able to figure that out. I'm not lazy, just learning!!


I have searched for an answer but cannot find one. I'm hoping someone can help.


Thanks in advance!





Create and Delete input type text if the selected input type checkbox

I have a problem, I need to create or delete as appropriate, a Input type text if a Input type checkbox is selected.


At the moment I can only create the input text, but I manage to find the solution to clear if the checkbox is unchecked.


My HTML code:



<form role="form" action="" method="POST">
<input type="checkbox" class="myCheckBox" name="category[]" value="1">
<input type="checkbox" class="myCheckBox" name="category[]" value="2">
<input type="checkbox" class="myCheckBox" name="category[]" value="3">
<input type="checkbox" class="myCheckBox" name="category[]" value="4">
<input type="checkbox" class="myCheckBox" name="category[]" value="5">
<div class="inputCreate"></div>
<input type="submit" name="" value="Send yours categories">
</form>


And the jQuery code is as follows



var wrapper = $(".inputCreate");

$('.myCheckBox').click(function() {
if ($(this).is(':checked')) {
$(wrapper).append('<input type="text" name="mytext[]" placeholder="">');
}
});


As I can do that by unchecking the checkbox, also delete the input text field ?.


Greeting From Chile.





samedi 28 mars 2015

Prevent a checkbox from being checked (not simply uncheck)

Under certain conditions a checkbox I have will display an error. I'm trying do disable the checkbox unless certain conditions are met.


I've tried the following



private void checkBox66_CheckedChanged(object sender, EventArgs e)
{
if (dataGridView3.RowCount == 0)
{
checkBox66.Checked = false;
}
}


But I realized this actively checks the box, before realizing any kind of uncheck. I need to make sure the checkbox ignores any clicks on it while the rowcount is 0





Newbie to Javascript: how to avoid sending data that have not changed?

I'm a newbie Javascript learner and I want to post serialized data of input checkboxes. The data are sent to the server in order to update the corresponding field in SQL table. Later, the user can review the selections he made the first time and deselect some checkboxes. If I understand well, only the selected items will be sent, not the unselected ones. How can I send all the info I need to update the newly selected items and the newly unselected ones?


The only solution I found is to make 2 updates: the first resets to 0 all the rows and the second one sets to 1 the selected items (newly selected or not) that are sent in the serialized array. Is there a more optimal way to do the job? Ideally, I would update only the data that have changed. Is it possible?


Regards, Patrick