dimanche 27 août 2017

Checkbox submits only one checkbox value

I have a form with multiple checkboxes, say A, B, C, D. Sometimes i will want the user to select more than one checkboxes, say B and C. When I do that I will see only the last value 'C' in the database. How will I modify my codes below to have BC submitted to the database?

FORM

<form id="myform" method="post" action="check_trash.php">
<input type="text" name="afam" require />

A<input type="checkbox"name="get_value[]" value="A">  
B<input type="checkbox" name="get_value[]" value="B">  
C<input type="checkbox"name="get_value[]" value="C">  
D<input type="checkbox" name="get_value[]" value="D">

<button id="subm" name="upload" style="color:#fff; padding:5px 66px" class="btn btn-success" ><b>Save</b></button>
</form>

Jquery

$("#subm").click( function() {

$.post( $("#myform").attr("action"), $("#myform").serialize(), function(info){ $("#result").html(info); } );
clearInput();
});

$("#myform").submit( function() {
    return false;
});

function clearInput() {
$('#myform').each(function(){
this.reset();
});    
}

PHP

if(!empty($_POST["get_value"])){
foreach($_POST["get_value"] as $checkbox){
}
$name = $_POST['myname'];
$insert_query = "insert into trash (checkbox,name) values ('$checkbox','$name')";

$run_query = mysqli_query($con, $insert_query);
if($run_query){
    echo "Submitted successfully";
}
else {
    echo "failed";
}
}

else{
echo "<script>alert('Please select at least one option!')</script>";
}




Fetching multiple check box items and its corresponding text box value in JSP

I am a beginner and I am trying to do the following I have a JSP page which fetches records from database. the records are displayed with a checkbox and also an additional input text box field. I want user to select multiple records and then a submit button which on clicking will put the selected checkbox table records(all fields) and the textbox item to a bean object Since there will be multiple checkboxes I am not sure how to add the records




samedi 26 août 2017

Check CheckBox inside inner Repeater from outer Repeater checked in Asp.Net

There are two CheckBoxes one is in outer Repeater and other is inside inner Repeater.

I would like to automatically check CheckBox of inner Repeater when checked the outer Repeater's CheckBox.

HTML Markup:

<asp:Repeater ID="repOuter" runat="server">
    <ItemTemplate>
        <asp:CheckBox ID="chkOuter" runat="server" 
             OnCheckedChanged="chkOuter_CheckedChanged" />

        <asp:Repeater ID="repInner" runat="server">
            <ItemTemplate>
                <asp:CheckBox ID="chkInner" runat="server" />
            </ItemTemplate>
        </asp:Repeater>

    </ItemTemplate>
</asp:Repeater>

Code-Behind

protected void chkOuter_CheckedChanged(object sender, EventArgs e)
{
    // can't have access to inner CheckBox placed inside Inner Repeater
    CheckBox innerCheckBox; // how?

    innerCheckBox.Checked = true; // want to check it
}




Set User Preference from checkbox Symfony

I need help. I have 3 entities: Customer OneToMany Preference ManyToOne Typology.

Customers must be able to set their own user 'Preferences' via a 'Typologies' checkbox. Preferences can be changed when the user wants it.

The form should show preferences in the db as checked.

I'm new of Symfony and I don't know how to do this. How do I build the form? How can I handle data in db?

Here the entities:

Preference.php

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Preference
 *
 * @ORM\Table(name="preference", indexes={@ORM\Index(name="fk_preference_typology1_idx", columns={"typology_id"}), @ORM\Index(name="fk_preference_customer1_idx", columns={"customer_id"})})
 * @ORM\Entity
 */
class Preference
{
    /**

     *
     * @ORM\Column(name="id", type="integer", length=45)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="date", type="datetime", nullable=true)
     */
    private $date;

    /**
     * @var \AppBundle\Entity\Customer
     *
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Customer")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="customer_id", referencedColumnName="id")
     * })
     */
    private $customer;

    /**
     * @var \AppBundle\Entity\Typology
     *
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Typology")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="typology_id", referencedColumnName="id")
     * })
     */
    private $typology;

    /**
     * @return Customer
     */
    public function getCustomer()
    {
        return $this->customer;
    }

    /**
     * @param Customer $customer
     */
    public function setCustomer($customer)
    {
        $this->customer = $customer;
    }

    /**
     * @return Typology
     */
    public function getTypology()
    {
        return $this->typology;
    }

    /**
     * @param Typology $typology
     */
    public function setTypology($typology)
    {
        $this->typology = $typology;
    }


}

Typology.php

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Typology
 *
 * @ORM\Table(name="typology")
 * @ORM\Entity
 */
class Typology
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="value", type="string", length=100, nullable=false)
     */
    private $value;


}

Thanks




Dynamic setting input type in Angular

Please can anybody explain why this code doesnt work, i try set input types dynamically, but this is not working.

//our root app component
import {Component, NgModule, VERSION} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
import { FormsModule }   from '@angular/forms';

@Component({
  selector: 'my-app',
  template: `
    <form #f="ngForm">

      <input [type]="rtype" value="beef" name="food" [(ngModel)]="myFood"> Beef
      <input [type]="rtype" value="lamb" name="food" [(ngModel)]="myFood"> Lamb
      <input [type]="rtype" value="fish" name="food" [(ngModel)]="myFood"> Fish
    </form>

    <p>Form value: </p>  <!-- {food: 'lamb' } -->
    <p>myFood value: </p>  <!-- 'lamb' -->
  `,
})
export class App {
  name:string;
  myFood = 'lamb';
  rtype='radio';
  constructor() {
    this.name = `Angular! v${VERSION.full}`
  }
}

@NgModule({
  imports: [ BrowserModule,FormsModule       ],
  declarations: [ App ],
  bootstrap: [ App ]
})
export class AppModule {}

also i try use type=, but this also doesnt work

I am read this http://ift.tt/2sTHNtK. But not understand why it is not working in Angular. May be angular not call http://ift.tt/2wQQdo6. Please explain.

Also when i create simple radio in html< and then try change the input type property from console it works fine for example was input.type="radio", became input.type="checkbox" in browser i see that radio changed to the normal checkbox.




PHP checkboxes database

I have been unable to get my code to after many hours of attempts. This is a very simple problem but i can't make sense of it so i have come here. So what my code does is check if the checkboxes have been checked and record it as a 1(false) or 2(true)Just look at the checkboxes My code below then should use that input to show the right tables from my database. This is the code that is broken (sorry about it being a image i could not figure out how to format code on this website

So what the problem is When only one checkbox is checked it shows the right table but if i check all 3 it shows only one (the one with printf("spell"))

Dose anyone have any idea what is going wrong.




How to make shiny group checkbox not reactive

I am building an app in shiny where user chooses conditions for analysis and also can filter data before analysis. So whenever he changes the dataset he also needs to reassign the checkboxgroup and it is a bit annoying. Is there a way to store the checkboxes values or make them not reactive?