lundi 9 mai 2022

how to get multiple checkbox value in edit form?

So, I have an edit form in that I have two checkboxes and i can store the data of both the checkboxes as comma separated in database and display it on JSP page but when I click on edit in my JSP page it redirects to the form with all the fields populated except the checkboxes now if only one of the checkboxes is selected i am able to get that value in edit but not when both of them are selected.

Can someone Please help regarding this issue ??

I'll add what i have tried so far.

Checkboxes using Semantic UI


    <div class = "error_placement_checkbox">
        <div align = "center" class="ui inverted form" id = "idcheckbox">
            <div align = "center" class=" inline required fields">
                <label> Product Availability </label>
                    <div class="field">
                        <div class="ui checkbox">
                            <input type = "checkbox" name = "p_act1" value = "In Stock" >
                            <label> In Stock </label>
                        </div>
                    </div>
                    <div class="field">
                        <div class="ui checkbox">
                            <input type = "checkbox" name = "p_act2" value = "Out Of Stock" >
                                <label> Out Of Stock </label>
                        </div>
                    </div>
            </div>
        </div>
    </div>

Jquery for retrieving first checkbox value only


        $(document).ready(function() {      
            $('input[name="p_act1"]').each(function(index){     
                if ($(this).val() == "<c:out value = '${product.p_act}' />")            
                ($(this).prop('checked' , true));
            });
        });

Jquery for retrieving second checkbox value only


        $(document).ready(function() {      
            $('input[name="p_act2"]').each(function(index){     
                if ($(this).val() == "<c:out value = '${product.p_act}' />")            
                ($(this).prop('checked' , true));
            });
        });

What I want is if user selects both the checkboxes, then in edit both of them should be selected. but now what's happening is if user has selected only one checkbox, only then in edit form I am getting one checkbox selected. but if user selects both checkboxes then in edit form both of them are not checked.




How do I insert multiple checkbox values into a data base with PHP ( PDO)?

so I attempt to insert the values of my checkbox into my database but I can't.. Can you help me please ?

This is the PHP Code

<?php
 
if(empty($_POST["choix"]))
{
echo "Il faut préciser le type d'abonnement";

}
else{
    
include "connectBdd.php";
try {
$sql="INSERT into abonee(nomabo,prenomabo,villeabo, adressmail_abo,adress_abo,abotel,codepostalbo) values(:nom,:prenom,:ville,:mail,:perso,:tel,:code)";
$resultat = $cnx->prepare($sql);
$nbLignes= $resultat->execute(array(":nom"=> $_POST["nom"],
":ville"=> $_POST["ville"],
":mail"=> $_POST["mail"],
":perso"=> $_POST["perso"],
":tel"=> $_POST["numero"],
":code"=> $_POST["code"],
":typeAbo"=>$_POST["choix"]) 
":prenom"=> $_POST["prenom"]));
 
 
echo $nbLignes." ligne ajoutée";

}
catch(PDOException $e) { // gestion des erreurs
echo"ERREUR dans l'ajout ".$e->getMessage();
}

}
?>

The problem here is that I generally use a foreach loop to extract the values of a checkbox but in this situation I can't because we are in a declaration of a array

Thank you everyone !




dimanche 8 mai 2022

TEXTBOX and CheckBox Filter Userform VBA

I'm stuck on a project. I have a project where my filter works with wildcard in the search. And I need Checkbox to work together with it. I believe my IF has a problem but I'm not able to elaborate a rationale if someone can help me with my project I'm very grateful My code is like this... I'm from Brazil and I'm having trouble solving this issue. If anyone can help me I would be very grateful!

Dim linhaa, linalist As Interior
Dim Valor_celula As String
Dim Criterio1, Cirterio2, Criterio3, Cirterio4 As String
Dim i As Long

'limpar filtro
frmMenu.lstvTeste.ListItems.Clear
ThisWorkbook.Sheets(2).Cells.ClearContents


'Apliocando o filtro 1
Select Case ComboBox1

'Empresa
Case ThisWorkbook.Sheets(1).Range("a2").Text
colunac1 = 0

'Tipo de Informação
Case ThisWorkbook.Sheets(1).Range("a3").Text
colunac1 = 1

'Resposta da Informação
Case ThisWorkbook.Sheets(1).Range("a4").Text
colunac1 = 2

Case ThisWorkbook.Sheets(1).Range("a5").Text
colunac1 = 3

Case ThisWorkbook.Sheets(1).Range("b6").Text
colunac1 = 4

End Select

If frmMenu.ComboBox2.Value = "" Then
colunac1 = 3
End If

'-----------------------------------------
'Apliocando o filtro 2
Select Case ComboBox2

'Empresa
Case Planilha1.Range("b2").Text
colunac2 = 1

'Tipo de Informação
Case Planilha1.Range("b3").Text
colunac2 = 2

'Resposta da Informação
Case Planilha1.Range("b4").Text
colunac2 = 3

End Select

If frmMenu.ComboBox2.Value = "" Then
colunac2 = 2
End If

'---------------------------------------------
ThisWorkbook.Activate

Planilha1.Select
plan = Planilha1.Name

Dim LinhaListbox, linha As Long

LinhaListbox = 1
linha = 2

Ln = 1

Dim ultimalinha As Range
Set ultimalinha = Planilha1.Range("a100000").End(xlUp)

With Sheets(plan)

Valor_celula = .Cells(linha, 2).Value


'---------------------teste---------------------------------------
**Do While linha <= ultimalinha.Row And _
 .Cells(linha, 2).Value <> ""
Valor_celula = .Cells(linha, 2).Value
'---------------------------------Alinhamento de criterios--------------------------------
'Criterio 1 GRSA ALIMENTAÇÃO
If frmMenu.chk1GRSA_ALIMENTAÇÃO.Value = True Then
Criterio1 = "GRSA ALIMENTAÇÃO"
Else
Criterio1 = "FALSE"
End If
'Criterio 2 GR MANUTENÇÃO
If frmMenu.chk2GR_MANUTENÇÃO.Value = True Then
Criterio2 = "GR MANUTENÇÃO"
Else
Criterio2 = "FALSE"
End If
'Criterio 3 FOODBUY
If frmMenu.Chk3FOODBUY.Value = True Then
Criterio3 = "FOODBUY"
Else
Criterio3 = "FALSE"
End If
'Criterio 4 GR CLEANMALL
If frmMenu.chk4CLEEAN_MALL.Value = True Then
Criterio4 = "CLEAN MALL"
Else
Criterio4 = "FALSE"
End If
'----------------------------------FIM ALINHAMENTO CRITERIOS----------------------------------
If UCase(Cells(linha, colunac1)) Like UCase("*" & (TxtBoxCampoPesquisa & "*")) And _
UCase(Cells(linha, colunac2)) Like UCase("*" & (TextBox2 & "*")) And _
UCase(Left(Valor_celula, Len(Criterio1))) = UCase(Criterio1) _
Or UCase(Left(Valor_celula, Len(Criterio2))) = UCase(Criterio2) _
Or UCase(Left(Valor_celula, Len(Criterio3))) = UCase(Criterio3) _
Or UCase(Left(Valor_celula, Len(Criterio4))) = UCase(Criterio4) _
Then
'
'Carrega informação para ListView
Set li = Me.lstvTeste.ListItems.Add(Text:=Planilha1.Cells(linha, 1))
li.ListSubItems.Add Text:=Planilha1.Cells(linha, 2)
li.ListSubItems.Add Text:=Planilha1.Cells(linha, 3)
li.ListSubItems.Add Text:=Planilha1.Cells(linha, 4)
li.ListSubItems.Add Text:=Planilha1.Cells(linha, 5)
End If
linha = linha + 1
Loop**
End With

End Sub```

  [1]: https://i.stack.imgur.com/eCLIv.png



checkboxes and state react-native

Im newbie who tries react native cant handle multiple checkboxes list and object state. i mean i need to change boolen prop in data (bool:) by pressing on certain checkbox.

what should i write in onPress? and do i need to use useEffect to re-render list? thank all beforehead!

data in useState

{
    title: "title1", 
    checkboxes: [
        {key:1, value: 1, bool: false,
            text: 'never'},
        {key:2, value: 1, bool: true,
            text: 'gonna'},
        {key:3, value: 2, bool: true,
            text: 'give'},
        {key:4, value: 2, bool: false,
            text: 'you'},
        {key:5, value: 3, bool: false,
            text: 'up'},
        {key:6, value: 4, bool: false,
            text: 'never'},
        ],
    },

react-native code

import React, {useEffect, useState, useReducer} from 'react';
import { View, Image, ImageBackground } from 'react-native';
import { useDispatch, useSelector } from 'react-redux';

import { Text, Button, CheckBox } from 'react-native-elements'; 
import { TouchableOpacity } from 'react-native-gesture-handler';
import * as functions from './helpers/functions';


export default function CheckListScreen (): JSX.Element {
  
  const [testData, setTestData] = useState(data); 
  
/* tried that 
  const [state, updateState] = useReducer(
    (state: any, updates: any) => ({
      ...state,
      ...updates,
    }),
    testData
  );*/

  return(
    <View style={styles.container}>
      
        <View style=>
          <Text style={styles.title}>{testData.title.toUpperCase()}</Text>
        </View>

        <View style=>
        {testData.checkboxes.map((item, key)=> //
          <View key={item.key} style={styles.checkbox}>
            <CheckBox 
            checked={item.bool}
            //onPress={updateState({testData})}
            //onPress={setCheckbox({...checkbox, checkbox[key] = true})}
            //onPress={setTestData(testData.checkboxes.map(()=>testData.checkboxes[key].bool = true))}
            //onPress={setTestData(()=> ({...item, item[key].bool = true}))} // testData.checkboxes[key].bool = true
            >
            </CheckBox>
            <Text style={styles.textCheckbox}>{item.text.toUpperCase()}</Text>
          </View>)}
        </View>
    </View>
  );
}



I want to add all the checked boxes into the listview in vb.net

i am not using checkedlistbox, i am using seperate check boxes.

eg- i want to add sandwiches,burger,pasta into the listview next to the menu




How to change text color of entire row in autotable

Anybody knows how to to change the text color of the specific row on #PDF_content3 based on the cell value of column 2... The table (called PDF_content3) in HTML has a checkbox on last cell. I want to change the text color of the entire row where checkbox has checked value.

Thank you.

Here is my script;

<script type="text/javascript">
function generate() { 
<?php
$path = $row['MODEL_PICTURE'];
$m_name = $row['MODEL_NAME'];
list($width, $height, $type, $attr) = getimagesize($row['MODEL_PICTURE']);
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
?>

var doc = new jsPDF('p', 'pt', 'a4');
var model_image = <?php echo json_encode($base64); ?>;
var model_width = <?php echo json_encode($width); ?> / 1.5;
var model_height = <?php echo json_encode($height); ?> / 1.5;
var model_name = <?php echo json_encode($m_name); ?>;
var pageHeight = doc.internal.pageSize.height;
var pageWidth = doc.internal.pageSize.width;

doc.text(model_name, pageWidth/2, 70, { align: 'center' });
doc.addImage(model_image, (pageWidth - model_width) / 2 , 100, model_width, model_height);
doc.autoTable(
    {  
    html: '#PDF_content2',
    margin: {left: 170},
    startY: model_height + 130,
    theme: 'grid',  
    columnStyles: {  
        0: {  
            cellWidth: 80,
            halign : 'center',
            fontSize: number = 10,
            
        },  
        1: {  
            cellWidth: 80,
            halign : 'center',
            fontSize: number = 10,
        },  
        2: {  
             cellWidth: 80,
             halign : 'center',
             fontSize: number = 10,
        }  
    },
}); 
doc.autoTable({  
    html: '#PDF_content3',
    startY: doc.lastAutoTable.finalY + 30,  
    theme: 'striped',  
    columnStyles: {  
        0: {  
            cellWidth: 410,
            fontSize: number = 8,
            cellPadding: Padding = 1,
        },  
        1: {  
            cellWidth: 70,
            halign : 'right',
            fontSize: number = 8,
            cellPadding: Padding = 1,
        },  
        2: {  
             cellWidth: 30,
             halign : 'right',
             fontSize: number = 8,
             cellPadding: Padding = 1,
        }  
    },
})  ;
doc.save('Pricing_Details.pdf');  
}
</script>

Here is the HTML Table

<table id="PDF_content3" class="table-striped table-bordered" style="padding-top: 20px; padding-bottom: 20px; width:-webkit-fill-available; ">
<thead>
<tr style="background-color: #263238; color: blanchedalmond;">
<th align="left" scope="col" colspan="1">Option Name</th>
<th align="center" scope="col" colspan="2">Option Prices</th>
</tr>
</thead>
<?php
  if ($_POST) {
            $sorgu = $baglanti->query("SELECT * FROM price_options WHERE OPTION_MODEL like '$selected' ");
            if($conn==0){
                while ($sonuc = $sorgu->fetch_assoc()) {
            ?>
                    <tr>
                    <td data-label="Option Name" align="left"><?php echo $sonuc["OPTION_NAME"] ?></td>
                    <td data-label="Option Price" align="right"><?php echo number_format($sonuc["OPTION_PRICE"]) ?></td>
                    <td data-label="Include" align="center"><?php echo "<input name='product' type='checkbox' onclick='totalIt()' value=" . $sonuc["OPTION_PRICE"] . ">" ?></td>
                    </tr>
                <?php
                
                
        }
    }
 } 
        ?>
</table>



samedi 7 mai 2022

React - What am i doing wrong about checkbox and axios?

It seems like i've a big misunderstanding of checkboxes/toggle. What I'm trying to do is, to change status of checkbox/toggle from true to false and otherway around.

The axios request working fine. I can change any text back and force. But when ever it comes to toggle a value I'm failing. It always ends in: I can set the value from false to true. But never from true to false.

My state shows correct value so when i click the toggle it shows in console: true, false, true, false...

But when I try to send it to the server and print console.log(req.body.isClosed); in my backend only in the case from false to true it will print a "true". From false to true it's a "undefined"

So ya here i am i tried since 5h to fix it. Used pure checkboxes, react-multi-switch-toggle and now mui switch... Hope someone can help me

const [isClosed, setIsClosed] = React.useState(false);

const handleIsClosed = (event) => {
 setIsClosed(event.target.checked);
};
<Switch
checked={isClosed}
onChange={handleIsClosed}
inputProps=aria-label
/>