samedi 31 janvier 2015

Symfony 2 / Twig and a collection of checkboxes

In my application I need to display a group of checkboxes with which the user can indicate certain selections. In my case it refers to "zones", i.e. Zone A, Zone B, Zone C, etc.


The problem I'm running into is how to construct this in my form type class using the FormBuilderInterface provided by the framework.


The documentation refers to a "collection" type [1] which seems what I need but I'm having trouble to connect the checkbox element [2]. The documentation only seems to give an example for a single checkbox but I need it for a group.


This is what I have so far (I've left out the other fields for brevity):



class FormType extends AbstractType {

public function buildForm( FormBuilderInterface $builder, array $options )
{
$builder
->add('zones', 'collection',
array(
'type' => 'checkbox',
'options' => array(
'zone-a' => 'Zone A',
'zone-b' => 'Zone B',
'zone-c' => 'Zone C',
)
)
)
;
}

}


And the data class (form model if you will):



class FormData {

protected $zones = [];

public function __construct( array $zones = NULL )
{
if( ! empty( $zones ) )
{
$this->setZones( $zones );
}
}

public function getZones()
{
return $this->zones;
}

public function setZones( $zones )
{
$this->zones = $zones;
}

}


This is how I render the form element (for now):



{{ form_row(form.zones) }}


However, the above only outputs a label named Zones and nothing else.


How do I correctly render a group/collection of checkboxes in a Symfony 2 / Twig application?


[1] http://ift.tt/1etmweE [2] http://ift.tt/1sffrAN





please answer this - someone answer this one please [on hold]

I've got a couple of issues here with setting up checkboxes and radio buttons.


First of all - when i submit it, the checkboxes never return the values that I've inputted in them (in this case, checked) - they still return the same list with check boxes, but this time, unchecked. Whereas the ones I want checked before submitting are not shown checked the second time...what do I do?


This is what the form looks like: ![This is what the form looks like:][1]


I want it to show ticked check boxes after I submit them.


Here's the releant HTML:



<br /><br />
<H2 align="center">SKILLS SET</H2>

<br />
<label for="skills" size="3">Pick Your Skill(s): </label>
<br /><br />
<tr>
<table border='1' cellspacing='0'>
<colgroup>
<col span='1'>
</colgroup>
<tr>
<td>Engineering Services</td>
<td>Information Technologies</td>
</tr> <!-- This one was missing -->
<tr>
<td valign="top">
<?php

$list = "SELECT * FROM skillsset WHERE category='Engineering' ORDER BY skills ASC";
//$list = "SELECT * FROM specifications ";
//$list1 = "SELECT * FROM specifications ORDER BY category ASC Limit 2";
$listAHI = $dbs ->prepare($list);
$listAHI -> execute();

//while($row1 = $listAHI1 ->fetch(PDO::FETCH_ASSOC)){
while($row = $listAHI ->fetch(PDO::FETCH_ASSOC))
{
$skills = $row["skills"];
$category = $row["category"];
echo "<input type='checkbox' name='skills[]' value='$skills'> $skills<br /> ";

//$category = $row["category"];
//$specifications = $row["specifications"];
//echo "$category <input type='checkbox' name='$specifications' value='$specifications'> $specifications </td>";
}

//while($row1 = $listAHI1 ->fetch(PDO::FETCH_ASSOC)){

//$category = $row1["category"];
//echo "<input type='checkbox' name='$specifications' value='$specifications'> $specifications ";
//echo "$category";

?>
</td>
<td valign="top">
<?php

$list = "SELECT * FROM skillsset WHERE category='Information' ORDER BY skills ASC";
//$list = "SELECT * FROM specifications ";
//$list1 = "SELECT * FROM specifications ORDER BY category ASC Limit 2";
$listAHI = $dbs ->prepare($list);
$listAHI -> execute();

//while($row1 = $listAHI1 ->fetch(PDO::FETCH_ASSOC)){
while($row = $listAHI ->fetch(PDO::FETCH_ASSOC))
{
$skills = $row["skills"];
$category = $row["category"];

echo "<input type='checkbox' name='skills[]' value='$skills'> $skills<br />";

//$category = $row["category"];
//$specifications = $row["specifications"];
//echo "$category <input type='checkbox' name='$specifications' value='$specifications'> $specifications </td>";
}

//while($row1 = $listAHI1 ->fetch(PDO::FETCH_ASSOC)){

//$category = $row1["category"];
//echo "<input type='checkbox' name='$specifications' value='$specifications'> $specifications ";
//echo "$category";
?>
</td>
</tr>
</table>


I want it to look something like this after I click the submit button:


![Desired outcome][2]


How do I make this work properly?


For text input - I used the following code: value="<?php if(isset($_POST['first_name'])) { echo $_POST['first_name']; } ?>"


However, for checkboxes, if I use that code, it gives me an error because



  1. it's a check box and

  2. it's being printed from a string which retrieves the list from a database in php my admin.


So how am I able to make it return the previously checked boxes after I click submit or save the data?


http://ift.tt/1CMuU2v http://ift.tt/1DiHGDT


here's my insert query - don't got an update query yet -


along with the arrays variable being imploded...



if (isset($_POST["submitd"]) && $_POST["submitd"] == "Save" ){ $specifications = implode(",",$_POST['specifications']); $skills = implode(",",$_POST['skills']);

$query567="INSERT into emprecords(id, first_name, middle_names, last_name, street, unit, city, region, postalcode, country, email, businessnumber, phonecountry, phonearea, phone, cellphonecountry, cellphonearea, cellphone, specifications, type, position, startingdate, desiredsalary, additionalinfo, skills, name, institution, instaddress, monthto, toyear, monthto1, toyear1, graduate, averages,company,position1, tasks, monthto2, toyear2, monthto3, toyear3, location,supervisor, startingsalary, endsalary, reasons, maywe, first_name1, middle_names1, last_name1, company1, relationship, email1, phone1, cellphone1, street1, unit1, city1, region1, postalcode1, country1) VALUES('$id', '$first_name', '$middle_names', '$last_name', '$street', '$unit', '$city', '$region', '$postalcode', '$country', '$email','$businessnumber', '$phonecountry', '$phonearea', '$phone', '$cellphonecountry', '$cellphonearea','$cellphone','$specifications','$type','$position','$startingdate','$desiredsalary','$additionalinfo','$skills', '$name', '$institution', '$instaddress', '$monthto', '$toyear', '$monthto1', '$toyear1', '$graduate', '$averages', '$company', '$position1', '$tasks', '$monthto2','$toyear2','$monthto3','$toyear3','$location','$supervisor','$startingsalary','$endsalary','$reasons','$maywe','$first_name1','$middle_names1','$last_name1','$company1','$relationship','$email1','$phone1','$cellphone1','$street1','$unit1','$city1','$region1','$postalcode1','$country1');";
$vttvk = $dbs -> prepare($query567);
$vttvk -> execute(array(':id'=>$id,':first_name'=>$first_name,':middle_names'=>$middle_names,':last_name'=>$last_name,':street'=>$street,':unit'=>$unit,':city'=>$city,':region'=>$region,':postalcode'=>$postalcode,':country'=>$country,':email'=>$email, ':businessnumber'=>$businessnumber,':phonecountry'=>$phonecountry, ':phonearea'=>$phonearea, ':phone'=>$phone, ':cellphonecountry'=>$cellphonecountry, ':cellphonearea'=>$cellphonearea, ':cellphone'=>$cellphone, ':specifications'=>$specifications, ':type'=>$type, ':position'=>$position, ':startingdate'=>$startingdate, ':desiredsalary'=>$desiredsalary, ':additionalinfo'=>$additionalinfo, ':skills'=>$skills, ':name'=>$name, ':institution'=>$institution,':instaddress'=>$instaddress,':monthto'=>$monthto,':toyear'=>$toyear,':monthto1'=>$monthto1,':toyear1'=>$toyear1,':graduate'=>$graduate,':averages'=>$averages,':company'=>$company,':position1'=>$position1,':tasks'=>$tasks,':monthto2'=>$monthto2,':toyear2'=>$toyear2,':monthto3'=>$monthto3,':toyear3'=>$toyear3,':location'=>$location, ':supervisor'=>$supervisor,':startingsalary'=>$startingsalary,':endsalary'=>$endsalary, ':reasons'=>$reasons, ':maywe'=>$maywe, ':first_name1'=>$first_name1, ':middle_names1'=>$middle_names1, ':last_name1'=>$last_name1, ':company1'=>$company1, ':relationship'=>$relationship, ':email1'=>$email1, ':phone1'=>$phone1, ':cellphone1'=>$cellphone1, ':street1'=>$street1, ':unit1'=>$unit1, ':city1'=>$city1, ':region1'=>$region1, ':postalcode1'=>$postalcode1, ':country1'=>$country1));




Running a function depending on check boxes

I'm trying to code a calculator that reacts to some tick boxes. The serving size will be multiplied by the different values in the tables below depending on which boxes are ticked. For example, in the ThickChiaYogurt table, 'Thick' is chosen in consistency, the 'Chia' tickbox is selected and the 'Yogurt' tickbox is selected.


The problem I'm having is that I can't seem to get it to do anything with the values.


Here's what the selection box code looks like:



<p>
<label style="font-family: arial" for="textfield">Serving Size (ml):</label>
<input type="text" name="textfield" id="ServingSize"> <?p>
<table width="250">
<tr>
<td><label style="font-family: arial">
<input type="checkbox" name="Settings" value="ChiaUsed" id="Chia">
Use Chia Seeds?</label></td>
</tr>
<tr>
<td><label style="font-family: arial">
<input type="checkbox" name="Settings_" value="YogurtUsed" id="Yogurt">
Use Yogurt?</label></td>
</tr>
<tr>
<td><label style="font-family: arial">
<input type="checkbox" name="Settings_" value="ProteinUsed" id="Protein">
Use Protein / Choc powder?</label></td>
</tr>
<p style="font-family: arial"> Consistency: <select><option>Thick</option>
<option>Medium</option>
<option>Runny</option></select> </p>


And the information I'm going to use against it:



var ThickChiaYogurt = [0.1, 0.38, 0.036, 0.43]
var MediumChiaYogurt = [0.1, 0.42, 0.036, 0.39]
var RunnyChiaYogurt= [0.08, 0.46, 0.036, 0.35]

// var NO CHIA = [ OATS, MILK, GREEK ]
var ThickYogurt = [0.15, 0.38, 0.45]
var MediumYogurt = [0.1, 0.42, 0.41]
var RunnyYogurt = [0.08, 0.46, 0.37]

// var NO GREEK = [ OATS, MILK, CHIA ]
var ThickChia = [0.23, 0.58, 0.036]
var MediumChia = [0.18, 0.61, 0.36 ]
var RunnyChia = [0.16, 0.64, 0.03 ]

// var NO GREEK OR CHIA = [ OATS, MILK ]
var Thick = [0.25, 0.6]
var Medium = [0.22, 0.63]
var Runny = [0.2, 0.65]

var Serving = 111
// OATS MILK GREEK CHIA POWDERS
var Output = [0, 0, 0, 0, 0]

function myFunction(Thick, Serving) {
return Thick[0] * Serving; }


Am I being dumb? It's my first day with JavaScript, so I feel like I'm hitting my head against a wall a bit.


I want it to tell users how much of each ingredient they should use after they've written in how big a serving they want and ticked the relevant boxes.


Thanks!





$_POST for checkbox

I have this form and its details need to be send in an email. As of now I have only managed to do the other fields to be included in the email but I am having a trouble with this multiple checkboxes. I have lots of checkboxes, 23 to be exact. Now, the problem I am encountering is, how will I include the value of the checkbox if one checkbox is checked or just two or three checkboxes are checked.


HTML



<input type="text" name="state" id="txt1">State:</input>
<input type="text" name="name" id="txt2">Name:</input>
Package A<input type="checkbox" name="radiog_dark" value="150.00" id="tcbx3" class="css-checkbox"/>
Package B<input type="checkbox" name="radiog_dark" value="175.00" id="tcbx3" class="css-checkbox"/>
Package C<input type="checkbox" name="radiog_dark" value="200.00" id="tcbx3" class="css-checkbox"/>


PHP



$state = $_POST['state'];
$entity = $_POST['entity'];

$email_message .= "State: ".clean_string($state)."\n";
$email_message .= "Entity: ".clean_string($entity)."\n";




OnCheckedChangeListener fires when scrolling down

I faced with a weird problem. I have an android application and it contains activity that includes ListViewAdapter. Each element contains a checkbox. And i have the following code:



public View getView(final int position, View convertView, ViewGroup parent) {

CheckBox checkbox = (CheckBox)v.findViewById(R.id.checkbox);
checkbox.setChecked(checked[position]);

checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener(){

public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// some code
}
});

}


And when i scroll my listview down my OnCheckedChangeListener fires and reset my checkbox if it was set. Why does it happend? I excpeted OnCheckedChangeListener will be triggered when i click checkbox manually or call setChecked programmatically but it does when i scroll down too. Why?





vendredi 30 janvier 2015

checkbox and radio buttons for rookies and pros

got a couple of issues here with setting up checkboxes - and radio buttons - first of all - when i submit it, the check boxes never return the values that i've inputed in them (in this case, checked) - they still return the same list with check boxes, but this time, unchecked - whereas the ones i want checked before submitting are not shown checked the second time...what do I do?


i'm confused!


here's a link to the image attached - http://ift.tt/1wKobzt link description here][1]


and I want it to show ticked check boxes after I submit them...here's the code for that below -



<br><br>
<H2 align="center">SKILLS SET</H2>

<br>
<label for="skills" size="3">Pick Your Skill(s): </label>
<br><br>
<tr>

<table border='1' cellspacing='0'>
<colgroup>
<col span='1'>
</colgroup>
<tr><td>Engineering Services
</td>
<td>Information Technologies
</td>
<tr>
<td valign="top">
<?php

$list = "SELECT * FROM skillsset WHERE category='Engineering' ORDER BY skills ASC";
//$list = "SELECT * FROM specifications ";
//$list1 = "SELECT * FROM specifications ORDER BY category ASC Limit 2";
$listAHI = $dbs ->prepare($list);
$listAHI -> execute();

//while($row1 = $listAHI1 ->fetch(PDO::FETCH_ASSOC)){
while($row = $listAHI ->fetch(PDO::FETCH_ASSOC))
{
$skills = $row["skills"];
$category = $row["category"];
echo "
<input type='checkbox' name='skills[]' value='$skills'> $skills<br>

";

//$category = $row["category"];
//$specifications = $row["specifications"];
//echo "$category <input type='checkbox' name='$specifications' value='$specifications'> $specifications </td>";

}

//while($row1 = $listAHI1 ->fetch(PDO::FETCH_ASSOC)){

//$category = $row1["category"];
//echo "<input type='checkbox' name='$specifications' value='$specifications'> $specifications ";
//echo "$category";



?>
</td>
<td valign="top">
<?php
$list = "SELECT * FROM skillsset WHERE category='Information' ORDER BY skills ASC";
//$list = "SELECT * FROM specifications ";
//$list1 = "SELECT * FROM specifications ORDER BY category ASC Limit 2";
$listAHI = $dbs ->prepare($list);
$listAHI -> execute();

//while($row1 = $listAHI1 ->fetch(PDO::FETCH_ASSOC)){
while($row = $listAHI ->fetch(PDO::FETCH_ASSOC))
{
$skills = $row["skills"];
$category = $row["category"];

echo "
<input type='checkbox' name='skills[]' value='$skills'> $skills<br>

";

//$category = $row["category"];
//$specifications = $row["specifications"];
//echo "$category <input type='checkbox' name='$specifications' value='$specifications'> $specifications </td>";

}

//while($row1 = $listAHI1 ->fetch(PDO::FETCH_ASSOC)){

//$category = $row1["category"];
//echo "<input type='checkbox' name='$specifications' value='$specifications'> $specifications ";
//echo "$category";



?>
</td>
</tr>
</table>


What do I gotta do to make this work properly? thnx a mill!! I want it to look like something in the image below after I click the submit button -


enter link description here


where did I go wrong?


For text input - I used the following code - value=""


however, for checkboxes, if I use that code, it gives me an error because 1. it's a check box and 2. it's being printed from a string which retrieves the list from a databse in php my admin...so how am I able to make it return the previously checked boxes after I click submit or save the data? thnx a mill once again!!!





Select a CheckBox in a ListBox by clicking on the background

I have a little problem with my ListBox

I can check a CheckBox by clicking on the text,

But if I click on the background I can't check my CheckBox

That make me feel so bad...


I suppose that I can create a method to solve my problem,

But I would like to know if there a property to fix this easily.

Thanks for helping.



<ListBox x:Name="DeleteEntreesListBox">
<CheckBox x:Name="myTextBox" Content="Hello"/>
</ListBox>


If my cursor is on the text the box is gray and can be check. Screen

If my cursor is not on the text but on the background the box is white and can't be check Screen





JQuery / JsPlump: toggle "hidden/visible" anchor with checkbox strarting from Hidden

i've wrote something using JsPlump Library.


I got three elements that start using



`display:none;`


and then i use the typical Jquery code for make them appear flagging a checkbox:



input type="checkbox" id="nameCB" name="nameCB" value="on"

$('#nameCB').click(function(){
this.checked?$('#elementID').show(1000):$('#elementID').hide(1000);


My problem is if i set an anchor for one of these elements:



jsPlumb.addEndpoint('elementID', {anchor:"BottomCenter" }, endpointOptions );


the anchor (in the default case is a gray circle) is always visible. I would like to make it visible ONLY when the element it is connected is visible.





View Holder pattern not working

I have implemented a custom listview in which I have two textviews and checkbox. These are encapsulated into a linear layout on whoms click I check/uncheck the checkbox. The problem I am facing is that when I click the linear layout, it checks the checkbox but it also checks other checkboxes on a fixed pattern i.e every 7-8 rows. I read many problems regarding it and found out that implementing a view holder would solve the problem but that's also not working for me. Following is my code:


CustomListAdapter:



public class ContactsListAdapter extends BaseAdapter{

private Context context;
private List<ContactInfo> contacts;
private List<ContactInfo> selectedContacts;

public ContactsListAdapter(Context context, List<ContactInfo> contacts) {
this.context = context;
this.contacts = contacts;
selectedContacts = new ArrayList<ContactInfo>();
}

public List<ContactInfo> getSelectedContacts() {
return selectedContacts;
}

@Override
public int getCount() {
// TODO Auto-generated method stub
return contacts.size();
}

@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return contacts.get(position);
}

@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return Long.parseLong(contacts.get(position).id);
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

final ViewHolder holder;

if(convertView == null) {
convertView = inflater.inflate(R.layout.contacts_list_row_item, null);
holder = new ViewHolder();
holder.view = (LinearLayout) convertView.findViewById(R.id.llContactRow);
holder.name = (TextView) convertView.findViewById(R.id.tvContactName);
holder.number = (TextView) convertView.findViewById(R.id.tvContactNumber);
holder.checkbox = (CheckBox) convertView.findViewById(R.id.cbMultipleSelect);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}

holder.name.setText(contacts.get(position).name);
holder.number.setText(contacts.get(position).number);
holder.view.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
ContactInfo contact = new ContactInfo();
contact.id = contacts.get(position).id;
contact.name = contacts.get(position).name;
contact.number = contacts.get(position).number;
holder.checkbox.setChecked(!holder.checkbox.isChecked());
if(holder.checkbox.isChecked()) {
selectedContacts.add(contact);
} else {
selectedContacts.remove(contact);
}
}
});

return convertView;
}

private static class ViewHolder {
LinearLayout view;
CheckBox checkbox;
TextView name;
TextView number;
}
}


What am I doing wrong? Please help.





Redirect if CheckBox is unchecked

I don't have any code for this, but would appreciate it if someone could provide an example of how the following could be coded.


I want to redirect a user to another URL (OnClick) if any/all of of the checkboxes are NOT checked. How can this be achieved?


If the user checks all the checkboxes then if (Page.IsValid) Response.Redirect to expected page.


Thanks in advance.





Insert array value into database

I have an array of checkboxes whose value I want to insert into a database. The checkbox declaration is like this:



echo '<td><input type="checkbox" name="check_list[]"
onClick="toggle(this, '.$x.')" /> All</td>';


And here I try to insert it (together with other variables, that doesnt really matter). So, the other variables are inserted, while this one isnt.



<?php
ob_start(); //eliminates buffer collisions
require_once('connect_db.php');
$id = time(); //creates a unique id using the unix time
$result = pg_query(connect(), "INSERT INTO lecturer VALUES ($id, '$_POST[name]','$_POST[surname]','$_POST[department]')");

$check = $_POST['check_list[0]'];
$availability = pg_query(connect(), "update lecturer set monday='$check'");

?>


What is wrong with my syntax? Cause all the values are inserted, besides that of the checkbox.





on checkbox check transfer data between tables accordingly

I have 2 tables one has Hobby_id and Hobby_name the other table has Id and selected_hobby field .I want to make a drop down with check box's bind with table 1 data. When i check the check box that value should get inserted in table number 2,And when i uncheck it again ,It gets removed from that table.





how can store the values of dynamically generated checkboxes in a table?

I have created a table of checkboxes. For each row, the first checkbox can check/ uncheck the rest of the row. Now I need to get the values of all the checkboxes (except from the first checkbox that selects all). From the values of each row I will generate a single number (taking the checkbox values as boolean values where Yes = 1 and No = 0). That will give me a number per row. Then these numbers will be stored in a table that has as many columns as there are rows of checkboxes. Value from first row will be stored in the first column and so on ...


This is the code that generates the table of checkboxes:



<?php
$days = array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
echo "<table border = 1px>";
//table header
echo "<tr>";
for ($i = 0; $i < 15; $i++){
echo "<th>";
if($i == 6) {$i++;}
if($i == 1) {echo "Check All";}
else if($i != 0) {
echo $i+6 . ":30 - "; echo $i+7 . ":30";
}
echo "</th>"; }
echo "</tr>";
//checkboxes are created here
for ($x = 0; $x < 6; $x++) {
echo "<tr>";
echo "<td>"; echo $days[$x]; echo '</td>'; //displays days
echo '<td><input type="checkbox" onClick="toggle(this, '.$x.')"/> All</td>'; //creates check all buttons
for ($y = 0; $y < 12; $y++)
echo '<td><input type="checkbox" name="'.$x.'" value="bar1"> Bar 1<br/></td>'; //creates the other buttons
echo "</tr>";
}
echo "</table>";
?>


I am not asking to have it all figured out. Only how to pass the values in my php file. Also, obviously there is a submit button that successfully posts the other data. I have fetched the other values from the other fields (which i haven't included in this code to make it look simpler). The method used is post and they are all stored correctly.


By the way, im using postgresql





checkboxes matrix with MVC4

I need to disply a matrix of checkboxes like the one in here asp.net mvc checkbox/radiobutton matrix model-binding


well, instead of subquestions I haves roles and types, so here is my code:


my models:



public class role
{
public role()
{
types = new List<role_type>();
}

[Key]
public int role_id { get; set; }
public string role_name { get; set; }
public int role_value { get; set; }
public Boolean IsSelected { get; set; }

public IList<role_type> types { get; set; }
}

public class role_type
{
public int Id { get; set; }
public Boolean IsSelected { get; set; }
public string type { get; set; }
}


My view Model:



public class roleViewModel
{
public roleViewModel()
{
Roles = new List<role>();
}
public int ID { get; set; }

public IList<role> Roles { get; set; }
}


My controller:



public class roleviewmodelController : Controller
{
private Context db = new Context();

[HttpGet]
public ActionResult Index(roleViewModel rvm)
{
return View(rvm);
}
}


and my view



@model UsersManagement.Models.roleViewModel
@{
ViewBag.Title = "Index";
}


@for (var i = 0; i < Model.Roles.Count(); i++)
{
<div id="roles">
<ul>
@for (var j = 0; j <4; j++)
{
<li>@Html.CheckBoxFor(m=>Model.Roles[i].types[j].IsSelected)</li>
}
</ul>
</div>
}


this doesn't display anything, what am i missing?


the types should be like (Edit, Delete, Read, Create) and the roles like: manage companies, manage invoices, etc...


PS: My final goal is to customise the authorization system but this is another issue.





Two sets of checkboxes sending values to two hidden fields

I have two rows of four checkboxes each with a hidden text field. I am using jquery to process the data from the ticked checkbox and place the result in the fields. However when I tick one checkbox it places the value in both fields. I have placed 2 instances of the script in the head of the page each with their own unique id. All indications are that the script is working correctly. Works perfectly if I only use one set of checkboxes. However I need two instances of the same checkboxes on my page. Any ideas would be really appreciated.





how to update table without dublicates in codeigniter

Im trying to make update for checkboxes value with textboxes , i have already done update and its work but when im enabling new checkbox and put some value into textbox , value going inserting random times into mysql db. This is part from my view:



<fieldset>
<!-- Form Name -->
<legend>Изберете типове за имота</legend>

<!-- Multiple Checkboxes (inline) -->
<div class="form-group">
<div class="col-md-4">
<label class="checkbox-inline" for="checkboxes-0">
<?php echo form_checkbox('data[1][property_type_id]', '22', set_value('data[1][property_type_id]',$type[22]['property_type_id']), 'id="checkboxes-0"')?>
Пентхаус
</label>
<br>
<!-- Text input-->
<div class="form-group">
<div class="col-md-8">
<?php echo form_input('data[1][alt_txt]', set_value('data[1][alt_txt]', isset($type[22]['alt_txt'])?$type[22]['alt_txt']:''), 'class="form-control" id="cena" placeholder="Въведи цена"')?>
</div>
</div>

<label class="checkbox-inline" for="checkboxes-1">
<?php echo form_checkbox('data[2][property_type_id]', '21', set_value('data[2][property_type_id]', $type[21]['property_type_id']), 'id="checkboxes-1"')?>
Гараж/Паркомясто
</label>
<br>
<!-- Text input-->
<div class="form-group">
<div class="col-md-8">
<?php echo form_input('data[2][alt_txt]', set_value('data[1][alt_txt]', isset($type[21]['alt_txt'])?$type[21]['alt_txt']:''), 'class="form-control" id="cena" placeholder="Въведи цена"')?>
</div>
</div>


and this is my save function



public function save_dynamic($data, $id)
{
// Delete all
$this->db->where('property_id', $id);
$this->db->where('value !=', 'SKIP_ON_EMPTY');
$this->db->delete('property_value');

// Insert all
$insert_batch = array();
// Process the POST DATA from the FORM
foreach($data as $key=>$value)
{
// Do this if the key is called option
if(substr($key, 0, 6) == 'option')
{
$pos = strpos($key, '_');
$option_id = substr($key, 6, $pos-6);
$language_id = substr($key, $pos+1);

$val_numeric = NULL;
if( is_numeric($value) )
{
$val_numeric = intval($value);
}

$insert_arr = array('language_id' => $language_id,
'property_id' => $id,
'option_id' => $option_id,
'value' => $value,
'value_num' => $val_numeric);

if($value != 'SKIP_ON_EMPTY')
$insert_batch[] = $insert_arr;

/*
$this->db->set(array('language_id'=>$language_id,
'property_id'=>$id,
'option_id'=>$option_id,
'value'=>$value));
$this->db->insert('property_value');
*/
}
}
// getting info from checkboxes
$data1=$this->input->post('data');
if(count($insert_batch) > 0) {
$this->db->insert_batch('property_value', $insert_batch);
}

// We need to loop through each entry and add in the property_id

// inserting 1 by 1
$insert_array = array();
$property_id = array('property_id'=>$id);
foreach($data1 as $array){
if(array_filter($array)){
$insert_array[] = array_merge($array,$property_id);

}
}
if($this->db->affected_rows() > 0) {
if(!empty($insert_array)){
foreach ($insert_array as $key=>$arrayche){

$this->db->where('property_type_id',$arrayche['property_type_id']);
$this->db->update('property_type_details', $arrayche);
}


}


inserting begins where is comented to //inserting 1 by 1 and second problem is when i uncheck checkbox its not updated with NULL the table..





jeudi 29 janvier 2015

Having Issue On Deselecting Above Checkboxes (None Of Above)

Can you please take a look at this demo and let me know how I can fix the code for last checkbox in a way to deselect all of above checkboxes when check and do nothing on un check statues?



<input id="selectAll" type="checkbox" name="slectAll">
<label for="selectAll">Yes, Select All</label>
<fieldset id="group_1">
<input type="checkbox" name="numbers[]" value="0" />Item 1<br />
<input type="checkbox" name="numbers[]" value="1" />Item 2<br />
<input type="checkbox" name="numbers[]" value="2" />Item 3<br />
<input type="checkbox" name="numbers[]" value="3" />Item 4<br />
<input type="checkbox" name="numbers[]" value="4" />Item 5<br />
</fieldset>
<input id="planB" type="checkbox" name="planB">
<label for="planB">I am not Sure</label>

<script>
$(function() {
var $all = $('input:checkbox[name=slectAll]').change(function() {
$checks.prop("checked", this.checked);
});

var $checks = $('#group_1 :checkbox').change(function() {
$all.prop("checked", $checks.not(':checked').length == 0);
});

var $none = $('input:checkbox[name=planB]').change(function() {
$checks.prop("checked", this.checked);
});

});
</script>


Thanks





kendo dropDownList onclick of text change event not firing

I am using kendo UI. I have a dropdown list of checkboxes. The onchange event is fireing when user clicks on checkbox. But the event is not firing when user clicks on text.


Thanks in advance for ur help! -Sai.



<script type="text/x-kendo-template" id="CheckboxTemplate">
<li unselectable="on" class="k-item nowrap check-item">
<input type="checkbox" name="#= text #" value="#= value #" class="check-input showcolname" checked />
<span>#= text #</span>
</li>
</script>


function populateDropdown() {
dropdown = $("#dropDownList").kendoDropDownList({
dataTextField: "text",
dataValueField: "value",
template: $("#CheckboxTemplate").html(),
dataSource: displayColumns,
placeholder: "Select...",
select: function(e) {
e.preventDefault();
}
}).data("kendoDropDownList");

dropdown.list.width(250);

dropdown.list.find(".check-input,.check-item").bind("click", function(e) {
var $item = $(this);
var $input;
if($item.hasClass("check-item")) {
// Text was clicked
$input = $item.children(".check-input");
$input.prop("checked", !$input.is(':checked'));
} else {
// Checkbox was clicked
$input = $item;
}
// Check all clicked?
if($input.val() == "") dropdown.list.find(".check-input").prop("checked", $input.is(':checked'));
syncColumns();

e.stopImmediatePropagation();
});

}


function syncColumns(){



$('.showcolname').each(function() {
$(this).change(function(event) {
event.preventDefault();
var val = $(this).val();
var url = "${rootContext}${MyUrl}/"+val+"/"+this.checked;
var beforeSendCallBack = function() {};
var successCallback = function(data) {};
submitPost(url, beforeSendCallBack, successCallback, '','');
});
});


}





SQL Command and Checkbox?

This doesn't work.



cmd.Parameters.Add("@Result", OleDbType.VarChar).Value = Me.cb_Result.Text


What datatype would it be, I've tried using .VarChar and .Boolean but they both do not work for a checkbox. The @Result is a YES/NO format field in the access database.





Click Label if checkbox prop check is true

All check boxes by default are unchecked. I cannot use radio buttons in the problem.


When a checkbox is changed to 'checked' then look to see if any of the sibling checkboxes are 'checked', if it is then .click() the parent <label> of the checkbox.


I have to .click() the <label> because the connected API is listening for a click on the label, $('input').prop("checked", false); doesn't seem to work.


Here is the structure:



<div class="feature-filter">
<div id="filterHandle">Product Filter</div>
<label class="featureLabel">
<input class="featureCheck" type="checkbox">
Original Pouch
</label>
<label class="featureLabel">
<input class="featureCheck" type="checkbox">
Original Can
</label>
<label class="featureLabel">
<input class="featureCheck" type="checkbox">
Gold Pouch
</label>
<label class="featureLabel">
<input class="featureCheck" type="checkbox">
Gold Can
</label>
<label class="featureLabel">
<input class="featureCheck" type="checkbox">
Menthol Pouch
</label>
<label class="featureLabel">
<input class="featureCheck" type="checkbox">
Menthol Can
</label>
</div>


This is what i tried but it's wrong.



$('.featureCheck').click(function(){

if $('.featureCheck').siblings().prop('checked',true){
this.find('label').click();
}

});




How do I switch out a DropDownList with a CheckBox in asp.net mvc3?

I'm new to mvc and was wondering if there was a way to switch out a DropDownList with a CheckBox. In my database I've got a property with a datatype of bit. In Visual Studios, after I create my model and controller and run it, it shows up as a DropDownList with True and False. I'd like this to be just a Checkbox instead of a DropDownList for both the Index and the Create views. I also (obviously) need it to bind to the database after creating a new item. I'm sure there is a way to achieve this, I just haven't been able to find the answer. Thanks guys!





Knockout.js data-bind array to list of checkboxes


Patient 1
Patient.Age = '25'
Patient.Injury[0].Date = '2015-01-01'
Patient.Injury[0].Type = 'Burned'
Patient.Injury[1].Date = '2015-01-27'
Patient.Injury[1].Type = 'Sprained Ankle'

Patient 2
Patient.Age = '17'
Patient.Injury[0].Date = '2015-01-08'
Patient.Injury[0].Type = 'Papercut'

<!-- ko foreach: Patient -->
<input type="checkbox" data-bind="checked: ?"> Sprained Ankle
<input type="checkbox" data-bind="checked: ?"> Burned
<input type="checkbox" data-bind="checked: ?"> Papercut
<!-- /ko -->


Looping through an array of multiple patients and displaying a list of checkboxes of injury types of each patient. How do I select multiple checkboxes per patient, based off of sub-array of injuries?





HTML Checkbox automatically send POST

I'm trying to collect checkbox data without adding button to submit.


This is the code I have so far:





<!-- Web form -->
<form class="switcher-form" method="post">
<p class="setting-switch setting-switch-first">
<label for="setting1">Controle Total</label>
<!-- switcher checkbox #1 -->
<input type="checkbox" class="switcher" checked name="setting1" value="1" onclick="submit();"/>
</p>

<p class="setting-switch">
<label for="setting2">Controle Sala</label>
<!-- switcher checkbox #2 -->
<input type="checkbox" class="switcher" checked name="setting2" value="2" onclick="submit();"/>
</p>

<p class="setting-switch">
<label for="setting3">Controle Quarto A</label>
<!-- switcher checkbox #3 -->
<input type="checkbox" class="switcher" checked name="setting3" value="3" onclick="submit();"/>
</p>

<p class="setting-switch">
<label for="setting4">Controle Quarto B</label>
<!-- switcher checkbox #4 -->
<input type="checkbox" class="switcher" checked name="setting4" value="4" onclick="submit();"/>
</p>

<p class="setting-switch">
<label for="setting5">Controle Cozinha</label>
<!-- switcher checkbox #5 -->
<input type="checkbox" class="switcher" checked name="setting5" value="5" onclick="submit();"/>
</p>

<p class="setting-switch">
<label for="setting6">Controle Garagem</label>
<!-- switcher checkbox #6 -->
<input type="checkbox" class="switcher" checked name="setting6" value="6" onclick="submit();"/>
</p>

<p class="setting-switch">
<label for="setting7">Controle Portao</label>
<!-- switcher checkbox #7 -->
<input type="checkbox" class="switcher" checked name="setting7" value="7" onclick="submit();"/>
</p>

<p class="setting-switch">
<label for="setting8">Controle Refrigeracao</label>
<!-- switcher checkbox #8 -->
<input type="checkbox" class="switcher" checked name="setting8" value="8" onclick="submit();"/>
</p>
</form>
<!-- End: Web form -->



Is it possible to use method to POST or GET? Automatically send the the checkbox, ex: http://ift.tt/18yBw9Q


I'm not really good with CSS HTML JS, this code is running on microcontroller.





C# redirect to other page when gridview checkbox is ticked asp.net

i need you help guys,i have two pages and one with agridview with checkbox column, i want to redirect to the second page when the user tick the checkbox. here is my code :



<asp:BoundField DataField="BC_Description" HeaderText="Description">
<HeaderStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="2px" HorizontalAlign="Center" />
<ItemStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="2px" Width="290px"
HorizontalAlign="Left" />
</asp:BoundField>

<asp:BoundField DataField="Update_Comments" HeaderText="Comments">
<HeaderStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="2px" HorizontalAlign="Center"
Width="100px" />
<ItemStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="2px" Width="350px"
HorizontalAlign="Left" />
</asp:BoundField>

<asp:TemplateField HeaderText="Changed">
<HeaderStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="2px" HorizontalAlign="Center" />
<ItemStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="2px" Width="150px"
HorizontalAlign="Center" />
<ItemTemplate>
<asp:CheckBox ID="chkApprove" runat="server" />
</ItemTemplate>
</asp:TemplateField>


if (!IsPostBack)
{
ChangedBy = getInfo.GetUserDetails(compileUserDI);
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("chkApprove");

if (cb.Checked)
{
Response.Redirect("CompileVariance.aspx");
}
}




How do I write code to select/unselect all checkbox on selecting checkbox header of data grid WPF?

This question may seem very old but I am not able to solve myself.


I am new to WPF.


I am facing little issues on working with data grid in WPF. Previously I was comfortable with Windows forms.


I have added a checkbox column in data grid and added a checkbox in the header.


Now How do I write code to select/unselect all checkbox on selecting checkbox header?


I tried all the possible answers from other posts but I am unable to success on it. I am little confused somewhere.



<DataGrid AutoGenerateColumns="True" Height="204" HorizontalAlignment="Left" Margin="38,162,0,48" Name="dataGrid1" VerticalAlignment="Stretch" Width="729" AreRowDetailsFrozen="False" EnableColumnVirtualization="False" IsManipulationEnabled="False" CanUserAddRows="False" AutoGeneratingColumn="dataGrid1_AutoGeneratingColumn" RowHeight="26" ColumnHeaderHeight="26" FontSize="15">
<DataGrid.Columns>
<DataGridCheckBoxColumn >
<DataGridCheckBoxColumn.Header>
<CheckBox Name="SelectAll" ></CheckBox>
</DataGridCheckBoxColumn.Header>
</DataGridCheckBoxColumn>
</DataGrid.Columns>
</DataGrid>


What should I do next?





Any Change in textbox will automatically check the checkbox

Hi I have coded a Grid view where we have one checkbox and two textbox. My need is that as we make any change in textbox like modify text from 0 to 1, the Checkbox should get automatically checked. This code is in asp.net and this can be done by javascript or Jquery.


Need code to do this activity.





Keep the check in checkbox on page reload

I have the form:



foreach($array as $c){
echo '<tr><td>';
echo '<input type="checkbox" name="check[]" value="'.$c.'"';

if(isset($_POST['check'])){
echo 'checked="checked"';
}

echo '>';
echo '</td></tr>';
}


I want to keep the check mark in the same checkbox on page reload(in case an error occured).The problem is that this script checks all checkboxes , instead of checking only the one that have been checked previously.





Bootstrap checkboxes in Modal work only on every 2nd page

I have a problem witj Bootstrap checkboxes ina modal. I want to give the user different download options for an image in a modal. But the checkboxes are only working on every 2nd pageclick:


Modal:



<div class="modal fade" id="myModal{{id}}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<form method="post">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">Please choose the formats and size you want to download</h4>
</div>
<div class="modal-body">
<div class="container">
<div class="btn-group col-xs-12" data-toggle="buttons">
<label class="btn btn-default">
<input type="checkbox" autocomplete="off" name="jpeg" value="1">Jpeg
</label>
<label class="btn btn-default">
<input type="checkbox" autocomplete="off" name="gif" value="1">Gif
</label>
<label class="btn btn-default">
<input type="checkbox" autocomplete="off" name="png" value="1">Png
</label>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-default">Download</button>
</div>
</div>
</form>
</div>
</div>


and paging via ajax:



$.ajax({
...
...
success: function(data){
$('#qrouter').empty();
$('#qrouter').html(data);
}
});


I can't explain myself, why it is working only on every 2nd page click. Do i have to reset something?





How to insert value of the checkbox array into the database while the cheekboxs value also have been retrieved from the database?

I am retrieving the result of the query from the database. in which i have stored id of the record into the checkbox.


connect_errno){ die('coudn\'t connect to the database' . mysqli_connect_error()); } else{ $query = "select * from simple"; $result = $conn -> query($query); echo 'SelectIDNameSurname'; while ($row = $result->fetch_array(MYSQLI_ASSOC)) { echo ''; echo ""; echo "{$row['id']} "."{$row['Name']}"."{$row['Surname']}"; echo ''; } echo ''; echo "Fetched data successfully\n"; $limit = count('$checkbox'); echo $limit; for($i=0;!$limit > 0;$i++,$limit--){ $res = implode(",", '$checkbox'); $q1 = 'insert into joint_data values("'.$i.'","'.$res.'")'; if($conn -> query($query) == TRUE){ echo "Data Entered successfully\n"; } echo $i,$res; } } $result->free(); mysqli_close($conn); ?>

I was able to retrieve the data and store into the checkbox array successfully. now i want to insert the value of the checkbox into different table.How can i do that?





WPF Binding Two Checkboxes with IsChecked Property

I have a WPF UI, with the following elements:


WPF UI



  • The checked checkbox is in a DataGridRow.

  • The rest is in the DataGridRowDetails. (It contains a smaller DataGrid)


What I want to get done is to bind the two (shown by red arrows) checkboxes together, so that when one is checked, the other also gets checked, and vice-versa.


I have already taken a look at these questions:


1) WPF Binding with 2 Checkboxes


But when I try this, the click handlers stop working. (The checkboxes stop working altogether)


2) wpf bindings between two checkboxes


When I use triggers, one checkbox triggers the other, and it inturn triggers the other, and goes on.. UI gets stuck.


Sample of my code:



<DataGrid x:Name="DataGrid1">
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>


<CheckBox x:Name="SelectionCheckBox1" PreviewMouseLeftButtonDown="SelectionCheckBox1_PreviewMouseLeftButtonDown"
Loaded="SelectionCheckBox1_Loaded"
IsChecked="{Binding ElementName=HeaderCheckBox1, Path=IsChecked, Mode=TwoWay}">
</CheckBox>


</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<DockPanel LastChildFill="True">
<DataGrid>
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>


<CheckBox x:Name="HeaderCheckBox1" PreviewMouseLeftButtonDown="HeaderCheckBox_PreviewMouseLeftButtonDown"
IsChecked="{Binding ElementName=SelectionCheckBox1, Path=IsChecked, Mode=TwoWay}">
</CheckBox>


</DataTemplate>
</DataGridTemplateColumn.HeaderTemplate>
</DataGrid.Columns>
</DataGrid>
</DockPanel>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>


Concern : Because the second Checkbox appears only after the row is selected ( which means the other checkbox is selected), I am unable to find the second checkbox through VisualTreeHelpers also.


Some idea even leading to a possible solution will be much appreciated.





passing selected checkbox string to json android

I have two checkboxes


Customer, Employee


When the appropriate checkbox is checked by clicking on login button


based on the checkbox selection either Customer or Employee passed to json parser


so that along with username and password the role(Customer or Employee)of user should be compared with the mysql database with help of php


I have already implemented and tested Backend(html,php and myql)



CheckBox Customer, Employee;
uname = (EditText)findViewById(R.id.uname1);
upass = (EditText)findViewById(R.id.upassword1);
Customer = (CheckBox)findViewById(R.id.customer);
Employee = (CheckBox)findViewById(R.id.employee);
login = (Button)findViewById(R.id.login);




mercredi 28 janvier 2015

Slick Grid - Select all rows for processing Issue

I am facing the issue with slick grid when I select all the rows on the grid and submit the data for save. The data is processed in the backend properly but the columns which gets updated based on processing status does not get refreshed with the updated status when the grid renders back. This happens only when I select all the rows on the grid and process the data. What do you think could cause the issue?





checkbox name[] to jquery $.ajax

Why my checkboxes:checked don't return nothing? When I check the items stated below, and then submit the form (with preventDefault()), they have an 'error_class' added, instead of having it removed. While the rest of my other inputs behave normally if they're not empty.



<label class="label" id="label_contrat">Type de contrat recherché</label>
<input type="checkbox" name="contrat[]" value="CDI" class="contrat_checkbox" tabindex="113"> <label for="CDI" class="tag_contrat">CDI</label>
<input type="checkbox" name="contrat[]" value="CDD" class="contrat_checkbox" tabindex="114"> <label for="CDD" class="tag_contrat">CDD</label>
<input type="checkbox" name="contrat[]" value="Interim" class="contrat_checkbox" tabindex="115"> <label for="Interim" class="tag_contrat">Interim</label> <br />
<input type="checkbox" name="contrat[]" value="Saisonnier" id='saison_c' class="contrat_checkbox" tabindex="116"> <label for="Saisonnier" class="tag_contrat">Emploi Saisonnier</label>
<input type="checkbox" name="contrat[]" value="Autres" class="contrat_checkbox" tabindex="117"> <label for="Autres" class="tag_contrat">Autres</label>



<input type="checkbox" name="cgu_inscription" id="cgu_inscription" tabindex="140"/>
<label class="label" id='label_cgu'>J'accepte les <a href="#" id="CGU_link">CGU</a></label>



/* var contrat = []
$("input[name='contrat[]']:checked").each(function ()
{
contrat.push(parseInt($(this).val()));
});*/

var contrat = { 'contrat[]' : []};
$("input[name='contrat[]']:checked").each(function() {
contrat['contrat[]'].push($(this).val());
});

var cgu_inscription = $("#cgu_inscription:checked").val();


$.ajax({
type : 'POST',
url : "process.php",
data: {myOtherValues:myOtherValues, contrat:contrat, cgu_inscription:cgu_inscription}
}, dataType:"json"
})
.done(function(data) { }
// etc




access form control open on event

Here is what I'm hoping to accomplish in Microsoft Access 2013:


1) Create a form (Form "x") with a series of checkboxes (Checkbox "xA", "xB", "xC")


2) Create an event procedure so that upon selecting checkbox "xA", a new form/window will launch (form "x1") with additional controls (checkboxes, buttons, etc...) while keeping form "x" open. Similarly for checkboxes "xB" and "xC".


I've tried doing the following in VBA to no avail:


Private Sub xA_Click()


Me.xA.DefaultValue = False


If Me.xA = True Then


DoCmd.OpenForm (x1)


End If


End Sub


Sorry if the format above is incorrect. This is my first time and I'm having trouble with the code builder.





c# .NET 4.5 TreeView: How do I make child nodes have checkboxes?

I see there is a complicated answer for this question for .NET 2.0 but this is 4.5. Is there any way now to give specific child nodes in treeview a checkbox? I want there to be folder icons for the parent nodes with a + to expand, and underneath, I need items to check. One would think this is so common nowadays that this would be built right in as an option in 4.5.


I have a pre-populated TreeView and I'm just adding to existing parent nodes with the following inside a loop, I want these nodes to have checkboxes:



foreach (string[] group in grpList)
{
TreeNode[] list = treeView1.Nodes.Find(group[1], true);

if (list.Length != 0)
{
list[0].Nodes.Add(group[0]);
}
}




Show or Hide HTML Table based on Checkboxes Data, Laravel 4

I have an HTML table with the days of a week



|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday|
|data |data |---- |---- |---- |---- |--- |


And have a Relation, Route-Client, and I whant to show(or not show) the columns days respect the value 1 from among a checkboxes from the Table Route. I save the checkboxes data with 0 and 1, working day 1, free day 0, and I'm extracting those 0 and 1 with this method:


Inside a Form::open()



<td>Route:</td>
<select id="day" name="day" onchange="showDays()">
@foreach($route as $ro)
<option value="{{ $ro['id'] .','. $ro['monday'] .','. $ro['tuesday'] .','. $ro['wednesday'] .','. $ro['thursday'] .','. $ro['friday'] .','. $ro['saturday'] .','. $ro['sunday'] }}">
{{ $ro['name'] }}
</option>
@endforeach
</select>
<input id="id_route" type=hidden name="id_route">


Javascript Method



function showDays() {

var day = $("#day").val();
alert(day);

var days= day.slice(-13);
alert(days);

//I pass the respective binary number to the respective day

var monday= document.getElementById("monday");
monday= day.slice(-13,-12);
$("#monday").val(monday); //don't know if this can help me in other javascript function
alert(monday);

var tuesday= document.getElementById("tuesday");
tuesday= day.slice(-11,-10);
$("#tuesday").val(tuesday);
alert(tuesday);

var wednesday= document.getElementById("wednesday");
wednesday= day.slice(-9,-8);
$("#wednesday").val(wednesday);
alert(wednesday);

var thursday= document.getElementById("thursday");
thursday= day.slice(-7,-6);
$("#thursday").val(thursday);
alert(thursday);

var friday= document.getElementById("friday");
friday= day.slice(-5,-4);
$("#friday").val(friday);
alert(friday);

var saturday= document.getElementById("saturday");
saturday= day.slice(-3,-2);
$("#saturday").val(saturday);
alert(saturday);

var sunday= document.getElementById("sunday");
sunday= day.slice(-1);
$("#sunday").val(sunday);
alert(sunday);

}


Inside my HTML table:



<tr><!--I been thinking on doing something like this -->
<th <a id="monday" onchange="showDays()" value="{{$route['monday']}}">MONDAY</th>
<th <a id="tuesday" onchange="showDays()" value="{{$route['tuesday']}}">TUESDAY</th>
<th <a id="wednesday" onchange="showDays()" value="{{$route['wednesday']}}">WEDNESDAY</th>
<th <a id="thursday" onchange="showDays()"value="{{$route['thursday']}}">THURSDAY</th>
<th <a id="friday" onchange="showDays()" value="{{$route['friday']}}">FRIDAY</th>
<th <a id="saturday" onchange="showDays()" value="{{$route['saturday']}}">SATURDAY</th>
<th <a id="sunday" onchange="showDays()" value="{{$route['sunday']}}">SUNDAY</th>
</tr>


If i do it like this i get on the Headers of the table the numbers 1,1,1,1,1,1,1 which are the binary values of the last Route created on my DB(for the moment don't know how to make change those values, just show the last created).


I need respect the values 1 or 0 received on my th to decide if show the column or not show it, but I don't know how to do that, if someone can help me I will be really grateful! Thanks!





How to iterate through multiple responses from checkbox form item?

I am dumping the selections from a checkbox question into a Google Doc. For readability purposes, I would like to parse each selected response and inject a line break between the selected options. Checkbox responses appear to be comma delimited strings. Some response options have commas in the text.


How do I add line breaks between multiple select response options?





get Email addresses using check boxes without submitting the form

i'm using this code to get the email addresses of the users from the data base for an email page. without submitting the form is there a way to select the email addresses and fill up the to field in the email form???? the code part that i used to get the values for the check box is :



<form>
<?php $email="";
if ($result->num_rows > 0) {
// output data of each row
while($cat = $result->fetch_assoc()) { ?>
<tr>
<td><input type="checkbox" name="user" value="<?php echo $cat['email']); ?>" oncheck="<?php $email .= $cat['email'] .','; ?>"></td>
<td><?php echo ($cat['name']); ?> (<em><?php echo ($cat['email']); ?></em>)</td>
</tr>
<?php }
} ?>
</form>


and the code bit where the form that i assign the values are



<div class="6u 12u(3)">
<input type="email" name="email" id="email"
<?php if($email==""){ ?>
placeholder="Email" <?php }
else { ?> value="<?php echo $email; ?>"
<?php } ?> />
</div>


but the email address picks up the emails from all the check boxes on form load it self... can some one please help me on this... tried all possibles ways and now i'm lost with it.


many thanks





Is it posible to make an input checkbox a Bootstrap glyphicon?

Is it posible to make an input checkbox a Bootstrap glyphicon?


I want to make up the default checkboxes with a nice Bootstrap glyphicon. For example: glyphicon glyphicon-unchecked and when checked: glyphicon glyphicon-check.


I've tried this:



input[type='checkbox'] {
position: relative;
top: 1px;
display: inline-block;
font-family: 'Glyphicons Halflings';
font-style: normal;
font-weight: 400;
line-height: 1;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
content: "\e157";
}


But nothing happened..


I don't know if that's posible?





Store two mouse click positions on canvas when checkbox enabled

I have a checkbox at the moment where, when I click it, it should allow the user to click two places on a canvas, and then a messagebox with the coordinates of both clicks appear, and then the checkbox should uncheck itself. I've tried various things and keep running into a few problems.



  1. Checking the box is a RoutedEventArgs where as clicking on the canvas is a MouseButtonEventArgs.

  2. I'm unable to store the second mouse click (the first click appears twice); I've tried various for loops, while loops, etc.

  3. I'm unable to get the box to uncheck itself after the message box appears, regardless of where I put the .Checked == false. I get an error that says system.windows.etcetc.checked can only appaer on the left hand side of += or -=.


I'd like to handle the whole thing in a function related to the checkbox aka the routedeventargs and not a canvas click method.


I can figure out #2 but 1 and 3 have me stumped.


This is a sample of the method which is subscribed to from a canvas mousedown in the xaml:



public void get_Scaling(object sender, MouseButtonEventArgs e)
{
Point startPoint;
Point endPoint;

while (Scale_btn.IsChecked == true)
{
startPoint = e.GetPosition(canvas1);

endPoint = e.GetPosition(canvas1);

System.Windows.MessageBox.Show("Start point is" + startPoint + "and end point is" + endPoint, "test", MessageBoxButton.OK, MessageBoxImage.Information);
}
}




ExtJS5: Checkbox afterSubTpl wraps icon

The snippet below will not run on this site, but you can access a working demo here on JSFiddle.


I am trying to get the icon to appear to the right of the checkbox, but it appears to be wrapping. Is there a property that I need to set so that it will appear in-line? This worked in ExtJS4, but after I switched to ExtJS5 this does not work.


enter image description here


afterSubTpl Documentation



Ext.form.field.Checkbox -> config -> afterSubTpl


An optional string or XTemplate configuration to insert in the field markup after the subTpl markup. If an XTemplate is used, the component's render data serves as the context.



Code





Ext.require(['*']);

Ext.define('App.view.MainView', {
extend: 'Ext.panel.Panel',
xtype: 'mainView',
alias: 'widget.mainview',
title: 'Checkbox Template Example',
referenceHolder: true,
layout: {
type: 'border'
},
initComponent: function () {
var me = this,
tooltip = me.getHelpIconWithTooltip();
me.items = [{
region: 'center',
xtype: 'panel',
title : 'A Panel Title',
margin : 20,
bodyStyle: 'padding: 8px;',
layout : 'vbox',
items : [{
xtype: 'checkbox',
fieldLabel : 'Checkbox',
afterSubTpl: tooltip
}]
}],
me.callParent();
},

getHelpIconWithTooltip: function () {
return this.getFormIconWithTooltip('help-icon help-form-icon',
'This is a help tooltip...');
},

getFormIconWithTooltip: function (iconClassList, toolTipText) {
var getSpan = function(cl, qt) {
return '<span class="'+cl+'" data-qtip="'+qt+'"></span>';
}
return [
'<tpl>',
getSpan(iconClassList, toolTipText),
'</tpl>'
];
}
});

Ext.define('App.app.App', {
extend: 'Ext.app.Application',
name: 'App',
launch: function () {
Ext.create('Ext.Viewport', {
layout: 'fit',
flex: 1,
items: [{
xtype: 'mainview'
}]
});
}
});

Ext.onReady(function () {
Ext.application('App.app.App');
});



.help-icon {
display: inline-block;
background: url(http://ift.tt/1zXWb2B) -705px -1125px no-repeat;
width: 16px;
height: 16px;
}

.help-form-icon {
/*margin-left: 5px;*/
}



<link href="http://ift.tt/1zbKYsj" rel="stylesheet" />
<script src="http://ift.tt/1zbKYZh"></script>






How to show-hide div based on multiple class elements

I'm trying to create a "narrow down" piece of code to implement on an ecommerce site. The idea is that by checking/unchecking boxes the user will be shown links to products that fit. So far my code works with the exception that checking multiple boxes and then unchecking them doesn't allow all the divs to reappear.





function showMe (box) {

var chboxs = document.getElementsByName("c1");
var vis = "block";
for(var i=0;i<chboxs.length;i++) {
if(chboxs[i].checked){
vis = "none";
break;
}
}
var x = document.getElementsByClassName(box);
x[0].style.display = vis;
x[1].style.display = vis;
x[2].style.display = vis;
x[3].style.display = vis;
x[4].style.display = vis;
x[5].style.display = vis;
x[6].style.display = vis;
x[7].style.display = vis;
x[8].style.display = vis;
x[9].style.display = vis;
x[10].style.display = vis;
x[11].style.display = vis;
x[12].style.display = vis;
x[13].style.display = vis;
x[14].style.display = vis;
x[15].style.display = vis;
x[16].style.display = vis;
x[17].style.display = vis;
x[18].style.display = vis;
x[19].style.display = vis;
x[20].style.display = vis;
}



<h3 align="center">What Elcometer 456 is Right for You?</h3>

<form>
<input type="checkbox" name="c1" onclick="showMe('F')">Ferrous<br>
<input type="checkbox" name="c1" onclick="showMe('NF')">Non-Ferrous<br>
<input type="checkbox" name="c1" onclick="showMe('FNF')">Dual Ferrous/Non-Ferrous<br><br>
<input type="checkbox" name="c1" onclick="showMe('Scale1')">Range 0 - 60mils<br>
<input type="checkbox" name="c1" onclick="showMe('Scale2')">Range 0 - 200mils<br>
<input type="checkbox" name="c1" onclick="showMe('Scale3')">Range 0 - 500mils<br><br>
<input type="checkbox" name="c1" onclick="showMe('Integral')">Integral<br>
<input type="checkbox" name="c1" onclick="showMe('Separate')">Separate<br><br>
<input type="checkbox" name="c1" onclick="showMe('Elcomaster')">Includes Elcomaster Tech<br><br>

<div class="NF FNF Scale2 Scale3 Separate Elcomaster" style="display:block">Scale 1 Model E F</div>
<div class="F NF Scale2 Scale3 Separate Elcomaster" style="display:block">Scale 1 Model E FNF</div>
<div class="NF FNF Scale2 Scale3 Separate Elcomaster" style="display:block">Scale 1 Model B F</div>
<div class="F FNF Scale2 Scale3 Separate Elcomaster" style="display:block">Scale 1 Model B NF</div>
<div class="F NF Scale2 Scale3 Separate Elcomaster" style="display:block">Scale 1 Model B FNF</div>
<div class="NF FNF Scale1 Scale3 Separate Elcomaster" style="display:block">Scale 2 Model B F</div>
<div class="NF FNF Scale1 Scale2 Separate Elcomaster" style="display:block">Scale 3 Model B F</div>
<div class="NF FNF Scale2 Scale3 Separate" style="display:block">Scale 1 Model S F</div>
<div class="F NF Scale2 Scale3 Separate" style="display:block">Scale 1 Model S FNF</div>
<div class="NF FNF Scale2 Scale3 Separate" style="display:block">Scale 1 Model T F</div>
<div class="F NF Scale2 Scale3 Separate" style="display:block">Scale 1 Model T FNF</div>
<div class="NF FNF Scale2 Scale3 Integral Elcomaster" style="display:block">Model B F</div>
<div class="F FNF Scale2 Scale3 Integral Elcomaster" style="display:block">Model B NF</div>
<div class="F NF Scale2 Scale3 Integral Elcomaster" style="display:block">Model B FNF</div>
<div class="NF FNF Scale2 Scale3 Integral" style="display:block">Model S F</div>
<div class="F FNF Scale2 Scale3 Integral" style="display:block">Model S NF</div>
<div class="F NF Scale2 Scale3 Integral" style="display:block">Model S FNF</div>
<div class="NF FNF Scale2 Scale3 Integral" style="display:block">Model T F</div>
<div class="F FNF Scale2 Scale3 Integral" style="display:block">Model T NF</div>
<div class="F NF Scale2 Scale3 Integral" style="display:block">Model T FNF</div>

</form>






PHP Select single checkbox value from database and assign to a variable

I have in my table from database 3 rows of tinyint type which are called: option1,option2,option3. I want to assing them value to variables $int1,$int2,$int3. + I have in my script 3 checkboxes and I want to check if checkboxes value is equal with checkboxes value from database. For example: if checkbox1 is checked && checkbox2 is checked, in above if, if checkbox1 value == $int1 && checkbox2 value == $int2, I don't know how to make this in my script, can anybody help me? I don't put the script here because I don't have any checkbox in it.





manipulate python variable inside a GTK action listener

I'm trying to an action listener that is attached to a checkbox button. My goal is to toggle the variable value ( 0 or 1 ) whenever the checkbox is checked/unchecked.


I come from a C background and am fairly new to python. I've also been reading up on global variable but I cannot seem to grasp it.


I will do an example in C first :



//#includes

int test; //i could say public int test but it is public by default

int foo()
{
test = 1;
return test;
}
void main()
{
test = 0;
print (foo);
}


Some example python code is below.



class someRandomClass:

def on_checkbutton1_toggled(self, widget, data=None):
if test == 0:
test = 1
if test == 1:
test = 0

def __init__(self):
global test
test = 0

if __name__ == "__main__":
main = someRandomClass()
gtk.main()


Executing this python code and clicking on the checkbox throws an UnboundLocalError: local variable 'test' referenced before assignment


I've tried creating the global variable outside of a function but still inside the class - the same method as the example C code.





create table of checkboxes with select all option

I am creating a table of checkboxes, where the first column will contain checkboxes that can check / uncheck the current row.


This is my code so far, which is not working.



<!DOCTYPE html>
<html>
<head>

<script language="JavaScript">
function toggle(source, $id) {
checkboxes = document.getElementsByName($id);
for (var i = 0, n = checkboxes.length; i < n; i++) {
checkboxes[i].checked = source.checked;
}
}
</script>

</head>

<body>

<?php
echo "<table>";
for ($x = 0; $x < 3; $x++) {
$id = $x;
echo "
<tr>";
echo "
<td>";
echo '<input type="checkbox" onClick="toggle(this, $id)"/> Toggle All';
echo '
</td>
';
for ($y = 0; $y < 7; $y++){
echo "
<td>";
echo '<input type="checkbox" name=$id value="bar1"> Bar 1<br/>';
echo '
</td>
';
}
echo "
</tr>
";
}
echo "</table>";
?>

</body>
</html>


I am aware that the code might contain several errors and am trying to find them. In the meantime, i would appreciate any suggestions.





how to get the the multiple checkbox values using custom adapter in android

Hi In the below code I am display textview with checkboxes.Now When I am selecting single value it's returning the name of the textview same as second textview name also.


Now I want to return at a time multiple textview names based on checkbox selected values. Eg:suppose two users I am selecting user1,user2 these two I got selected I want to return these two names in single variable.


java



checkBoxState = new boolean[friend.length];
holder.check1.setChecked(checkBoxState[position]);
holder.check1.setOnCheckedChangeListener(new OnCheckedChangeListener(){

public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
checkBoxState[position]=isChecked;

if(isChecked){

check=friend[position].userName;
}
Toast.makeText(getApplicationContext(),friend[position].userName+"checked", Toast.LENGTH_LONG).show();
}
});




How to make window scrollable with checkboxes inserted vertically in order?

I want to make the window scrollable with checkboxes inserted vertically in order.


In the code below, checkboxes are displayed as I want, but the window is not scrollable. Any help would be appreciated.



JFrame frame;
frame = new JFrame();
frame.setBounds(100, 100, 150, 300);
frame.setResizable(false);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
frame.getContentPane().setLayout(null);

chckbxNewCheckBox = new JCheckBox[emratStudent.length];
JPanel panel = new JPanel();
panel.setBounds(0, 0, 150, 300);
panel.setLayout(null);
for (int i = 1; i < studentNames.length; i++) {
chckbxNewCheckBox[i] = new JCheckBox();
chckbxNewCheckBox[i].setText(studentNames[i]);
chckbxNewCheckBox[i].setBounds(0, (i-1)*25, 150, 23);
chckbxNewCheckBox[i].setBackground(Color.pink);
panel.add(chckbxNewCheckBox[i]);
}

JScrollPane scrollPane1 = new JScrollPane(panel);
scrollPane1.setBounds(0, 0, 130, 600);
frame.getContentPane().add(scrollPane1);




How to show checkbox only when getView( ) is called

Hello i'm developing simple todo list app..and I ran into this problem I want to show checkbox Dynamically but since i created it in my xml with following attributes...it is automatically shown and <CheckBox android:visibility="gone" android:layout_marginLeft="5dp" android:layout_marginTop="0dp" android:layout_width="353dp" android:layout_height="wrap_content" android:id="@+id/checkBox" android:checked="false" /> when i played with it,i figured out that listView's first row is being shown screen 1


screen2 screen3 notice a line below the button


i tried to change the visibility of checkbox but i think it is the issue with list view..



static class ViewHolder{
TextView textView;

ViewHolder(View v){
textView = (TextView) v.findViewById(R.id.textView);
}
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row= convertView;
ViewHolder holder = null;CheckBox checkBox;
if(row == null){//1st time
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.single_row,parent,false);
holder = new ViewHolder(row);
row.setTag(holder);
}
else{//recycling
holder = (ViewHolder) row.getTag();
}
MainActivity.Task singleTask= list.get(position);
holder.textView.setText(singleTask.getNote());

checkBox = (CheckBox) row.findViewById(R.id.checkBox);
//if(position >=0)
// checkBox.setVisibility(View.VISIBLE);

return row;
}


this is my arrayAdapter class... please help me with this...thanks in advance!!





Angularjs checkbox value on edit proflie page

I am new to angularjs and getting some problem on checkbox values on edit profile page.


I have an array for checkbox



$scope.checkBoxes = [
{id:'1', value:'Reading'},
{id:'2', value:'Cooking'},
{id:'3', value:'Dancing'},
{id:'4', value:'Singing'}
];


and I have used ng-repeat for showing checkbox



<div ng-repeat="checkBox in checkBoxes" style="display:inline;">
<input type="checkbox" ng-model="checkBox.selected" id={{checkBox.id}}' ng-checked="checkItem(checkBox.id)" ng-change="listActionsHandler(checkBoxes)">{{ checkBox.value }}
</div>


This is my ng-change function:



$scope.listActionsHandler = function(list) {
var has = [];
angular.forEach(list, function(item) {
if ( angular.isDefined(item.selected) && item.selected === true ) {
has.push(item.id);
}
});
formData['hobby'] = has;
}


and this is my ng-checked function that is used for showing checkbox checked according to database saved value.



var arr_checked_items = data.data.hobby;
var arraySize = arr_checked_items.length;
$scope.checkItem = function (id) {
var checked = false;
for(var i=0; i<= arraySize; i++) {
if(id == arr_checked_items[i]) {
checked = true;
}
}
return checked;
};


These function work properly on add and edit page, but problem is that when I doesn't apply any changes on checkbox and click on submit button it take blank value.


My question is that: if I does not apply any changes, it should take old value of checkbox and if I apply any changes, it should take new value of checkbox.





Razor CheckBoxFor model bool variable

I have a razor MVC project, i use TextBoxFor to set the data for the model im posting.


Now im trying to do the same thing for a CheckBox to set a bool value in my model, but it doesnt work.



@Html.CheckBoxFor(model => model.bringYourOwnDevice, new
{
@class = "form-control",
@id = "inputBringyourowndevice",
})

public class RegisterModel
{
bool bringYourOwnDevice { get; set; }
}


What am i doing wrong?





Angular UI Bootstrap accordion heading not working correctly with checkbox

I'm using a check box in the heading of the accordion control in bootstrap, but the model will only update the first time it's clicked. Here's the HTML for the accordion:



<accordion ng-repeat="timesheet in timesheets">
<accordion-group>
<accordion-heading>
Title
<input type="checkbox" ng-model="approvals.timesheetCheckbox" ng-click="approvals.timesheetChecked($event)"/>
</accordion-heading>
</accordion-group>
</accordion>


the click method is in my typescript controller:



timesheetChecked($event: Event) {
$event.stopPropagation();
$event.preventDefault();
}


If I just use the stopPropagation() method by itself it updates the model correctly and the check box is checked, however, it will then refresh the page. The preventDefault() method stops this from happening, but then it will then only update the model once and not check the check box.


I have tried using ng-bind and that will actually update the model with correctly, but it will not change the check box to checked.


If I use the check box outside of the accordion it works as expected and I have no problems with it. I'm not really sure what I am doing wrong here?





mardi 27 janvier 2015

jQuery check if one checkbox is checked and another unchecked

I got this HTML:



<input type="checkbox" id="checkw" "checked" />Woman<br>
<input type="checkbox" id="checkm" />Männer<br>


I want to find out if checkw is checked and checkm is unchecked so I tried different ways like:



if($('#checkw').prop('checked') || $('#checkm').prop('unchecked'))
{
alert("w");
}


and



if($('#checkw').is(':checked') || $('#checkm').is(':unchecked'))
{
alert("w");
}


and



if($('#checkw').is(':checked',true) || $('#checkm').is(':checked',false))
{
alert("w");
}


But I always get the alert when checkm is also checked. Any ideas?