vendredi 19 février 2021

Javascript checkboxes with the same class name

I would like to do when I check one checkbox the other checkboxes get disabled not the checked checkbox.

let checkbox = document.querySelector(".checkbox");

function check() {

    if (checkbox.checked) {
    checkbox.disabled = "true"
} 

}
 <input onclick="check()" class="checkbox" type="checkbox">
  <input onclick="check()" class="checkbox" type="checkbox">
   <input onclick="check()" class="checkbox" type="checkbox">
    <input onclick="check()" class="checkbox" type="checkbox">



jQuery checkbox validation in same class

I wonder if I can validate checkbox can be selected with only one option based on each question like the radio button. However, I am using the same class for all checkboxes even though they have different titles.

Is it possible to validate each question rather than validating with the class name? Here is the HTML and Jquery code below. Thanks in advance.

--- HTML ---

    <div><label class="k-checkbox-label" >Question 1</label> 
      <input type="checkbox" id="q1_yes" class="k-checkbox">
      <label class="k-checkbox-label" >Yes</label>
      <input type="checkbox" id="q1_no" class="k-checkbox uk-margin-left">
      <label class="k-checkbox-label" >No</label>
    </div>
    <div><label class="k-checkbox-label" >Question 2</label> 
      <input type="checkbox" id="q2_yes" class="k-checkbox">
      <label class="k-checkbox-label" >Yes</label>
      <input type="checkbox" id="q2_no" class="k-checkbox uk-margin-left">
      <label class="k-checkbox-label" >No</label>
    </div>
     <div><label class="k-checkbox-label" >Question 3</label> 
      <input type="checkbox" id="q3_yes" class="k-checkbox">
      <label class="k-checkbox-label" >Yes</label>
      <input type="checkbox" id="q3_no"class="k-checkbox uk-margin-left">
      <label class="k-checkbox-label" >No</label>
    </div>
     <div><label class="k-checkbox-label" >Question 4</label> 
      <input type="checkbox" id="q4_yes" class="k-checkbox">
      <label class="k-checkbox-label" >Yes</label>
      <input type="checkbox" id="q4_no" class="k-checkbox uk-margin-left">
      <label class="k-checkbox-label" >No</label>
    </div>

--- code ---

    $('input.k-checkbox').on('change', function() {
        $('input.k-checkbox').not(this).prop('checked', false);  
    });



WPF C# - multiple CheckBox controls in a DataGrid cell

In the DataGrid control I would like to add a column in which each cell would contain a list of checkbox controls (for each cell there can be a different number of such checkboxes with different descriptions). I don't know how to define such a column with an undefined number of checkboxes in a cell.

Please help.




Kivy: action when unclick a checkbox

I am creating a mobile app as questionary, my questions are in checkboxes. functions in my app make a list of answers and when the user choose certain answer it writes value into list.

Sometimes they can choose wrong answer and they want to repair their choice. i want to add function when they unclick a checkbox to delete last value in list

in .py

class test:

    def __init__(self, testovatel, test_v=[], ):
        self.testovatel = testovatel
        self.test_v = test_v

    def mistake(self):
        del self.test_v [len(self.test_v)-1]


class TestScreenV(Screen):
    
    jarka= test("jarka")

    def bad(self):
        if self.ids.check_test.active == False:
            self.jarka.mistake()

    def d_plus(self):
        self.jarka.test_v += ("d",)

    def i_plus(self):
        self.jarka.test_v += ('i',)

    def s_plus(self):
        self.jarka.test_v +=('s',)

    def k_plus(self):
        self.jarka.test_v +=('k',)

in .kv

<TestConfirm>
    on_release: root.set_icon(check_test)
    CheckboxLeftWidget:
        id: check_test 
<TestScreenV>:
    OneLineListItem:
        text: "1/24 "
                            
    TestConfirm:
        text: "bla"
        on_press: 
            root.d_plus()
            root.bad()
    TestConfirm:
        text: "bla"
        on_press: 
            root.k_plus()
            root.bad()
    TestConfirm:
        text: "bla"
        on_press: 
            root.s_plus()
            root.bad()
    TestConfirm:
        text: "bla"
        on_press: 
            root.i_plus()
            root.bad()



jeudi 18 février 2021

Currently I am working on React(Frontend Part), I have bookmark folder list, users able to select one or more bookmark files from the above list

Actual UI:- In the image, Selected bookmark files are there. My question is how can I show checkboxes instead of that folder icon () so that user can select the check box. Expecting UI:- I Need to change the folder icon to a checkbox. I changed but it isn't working, can anyone help me?

<BlockUI tag="div" blocking={foldersLoading}>
           <main id="candidates-list-container">
           {/* ref={(ref) => { mainBottom = ref; }}  */}
           <ul>
           {folders.map((folder) => {
           const folderID = folder.id;
           console.log(folderID);
           const folderName = folder.name;
           console.log(folderName);
           return (
             <li key={folderID}>
                <button
                  type="button"
                  className={`job ${
                     selectedFolders.indexOf(folderID) > -1 ? 'selected' : ''
                  }`}
                  disabled={
                     bookmarkedCandidate.is_bookmarked
                     && selectedFolders.indexOf(folderID) === -1
                  }
                  onClick={() => {
                     selectFolder(folderID, folderName);
                  }}
                 >
                 <h2
                   className={`${
                      selectedFolders.indexOf(folderID) > -1 ? 'selected' : ''
                      }`}
                 >
                 <input type="checkbox" className="jss1042" value="" />
                    {folderName}
                 </h2>
               </button>
             </li>
            );
           })}
         </ul>
        </main>
        </BlockUI>

In the image, Selected bookmark files are there. My question is currently, how can I show checkboxes instead of that folder icon () so that the user can select the check box. This is my code it doesn't work for me. Please help me, guys.




How to get checkbox values insert into multiple rows?

My code is inserting the checkbox values into one row - i would like to have the code insert multiple rows depending on number of checkboxes checked. Can any one tell me what im doing wrong?

I have tried implode, explode - but haven't had any succes so far. Please can any one tell me what i'm doing wrong. Hope fulle by modifing my code bellow...? Thx

  <?php
    // Initialize the session
    session_start();

    // Include config file
    require_once "assets/scripts/config.php";

    $param_uniqid = $_SESSION['uniqid']; 
    $param_company = $_SESSION['company']; 
    $param_vat = $_SESSION['vat']; 
    $param_username = $_SESSION['username']; 
 
    // Check if the user is logged in, if not then redirect him to 
    login page
    if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== 
    true){
    header("location: login.php");
    exit;
    }

    // Define variables and initialize with empty values
    $l_comps = $status_request = $user = $car = $uniqid = $company 
    = $vat = $username = "";
    $l_comps_err = $status_request_err = $user_err = $car_err = 
    $uniqid_err = "";
 
    // Processing form data when form is submitted
    if($_SERVER["REQUEST_METHOD"] == "POST"){

    {
    $l_compsarr = $_POST['l_comps'];
    $l_comps = implode(", ",$l_compsarr);
    } 

    {
    $status_request = ($_POST["status_request"]);
    }   

    // Validate user
    $input_user = trim($_POST["user"]);
    if(empty($input_user)){
        $user_err = "Venligst indtast en bruger.";
    } elseif(!filter_var($input_user, FILTER_VALIDATE_REGEXP, 
    array("options"=>array("regexp"=>"/^[0-9a-åA-Å\s]+$/")))){
        $user_err = "Bruger er ikke korrekt.";
    } else{
        $user = $input_user;
    }

    // Validate car
    $input_car = trim($_POST["car"]);
    if(empty($input_car)){
        $car_err = "Venligst indtast bilinformationer.";
    } elseif(!filter_var($input_car, FILTER_VALIDATE_REGEXP, 
    array("options"=>array("regexp"=>"/^[0-9a-åA-Å+&@#\/%-? 
    =~_|!:,.;\s]+$/")))){
        $car_err = "Bil er ikke korrekt.";
    } else{
        $car = $input_car;
    }
    
    // Validate uniqid
    $input_uniqid = trim($_POST["uniqid"]);
    if(empty($input_uniqid)){
        $uniqid_err = "Venligst indtast uniqid.";
    } elseif(!filter_var($input_uniqid, FILTER_VALIDATE_REGEXP, 
     array("options"=>array("regexp"=>"/^[0-9a-åA-Å+&@#\/%-? 
    =~_|!:,.;\s]+$/")))){
        $uniqid_err = "Uniqid er ikke korrekt.";
    } else{
        $uniqid = $input_uniqid;
    }
    
    
    // Check input errors before inserting in database
    if(empty($l_comps_err) && empty($status_request_err) && 
    empty($user_err) && empty($car_err) && empty($uniqid_err)){
        $sql = "INSERT INTO offer_requests (l_comps, 
    status_request, user, car, uniqid, company, vat, username) 
     VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
         
        if($stmt = mysqli_prepare($link, $sql)){
            // Bind variables to the prepared statement as 
    parameters
              mysqli_stmt_bind_param($stmt, "ssssssss", 
    $param_l_comps, $param_status_request, $param_user, 
    $param_car, $param_uniqid, $param_company, $param_vat, 
    $param_username);
            
            // Set parameters
    
            $param_l_comps = $l_comps;
            $param_status_request = $status_request;
            $param_user = $user;
            $param_car = $car;
            $param_uniqid = $uniqid;
    
            // Attempt to execute the prepared statement
            if(mysqli_stmt_execute($stmt)){
            
                // Records created successfully. Redirect to 
     landing page
                header("location: /offer_requests");
                exit();
            } else{
                echo "Something went wrong. Please try again 
     later.";
            }
        }
    }
    }

    ?>
 
    <!DOCTYPE HTML>

    <html>
    <head>
        <title>Fleets - få op til 3 tilbud på jeres næste 
    leasingbil</title>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, 
    initial-scale=1" />
        <link rel="stylesheet"
        <link rel="stylesheet" href="assets/css/main.css" />
    </head>
    <body class="subpage">

        <!-- Header -->
            <header id="header">
                <div class="logo"><a href="index.html">Fleets.dk <span>3 tilbud på leasingbil</span></a></div>
                <a href="assets/scripts/logout.php" class="code">LOG UD</a>
            </header>

    <!-- content -->
            <div class="box">
                <div class="inner">
                    <div class="content">
                            <h4>Hej, <b><?php echo htmlspecialchars($_SESSION["name"]); ?></b>.</h4>

                        <hr />

                        <ul class="nav nav-tabs">
                          <li role="presentation"><a href="/welcome">Profil</a></li>
                          <li role="presentation"><a href="/cars_employees">Biler</a></li>
                          <li role="presentation" class="active"><a href="offer_requests">Tilbud</a></li>
                        </ul>
                            
                            <div class="table-wrapper">
                            <h4 class="pull-left">Oprettede tilbud</h4>
                            
                <table class="table table-striped">
                    <tbody>
                        <tr>
                            <th class="hidden"><b>#</b></th>
                            <th><b>Bil</b></th>
                            <th><b>Leasingselskab(er)</b></th>
                            <?php
                            // Include config file
                            require_once "assets/scripts/config.php";
                            
                            // Attempt select query execution
                             $sql = "SELECT * FROM offer_requests WHERE username = '" . ($_SESSION["username"]) . "'";
                            if($result = mysqli_query($link, $sql)){
                                if(mysqli_num_rows($result) > 0){

                                                echo "<th></th>";
                                            echo "</tr>";
                                        while($row = mysqli_fetch_array($result)){
                                            echo "<tr>";
                                                echo "<th class='hidden'>" . $row['uniqid'] . "</th>";
                                                echo "<th>" . $row['car'] . "</th>";
                                                echo "<th>" . $row['l_comps'] . "</th>";
                                                echo "<th>";
                                                    echo "<a href='read_request.php?uniqid=". $row['uniqid'] ."' title='Se tilbudsanmodning' data-toggle='tooltip'><span class='glyphicon glyphicon-eye-open'></span></a>";
                                                echo "</th>";
                                            echo "</tr>";
                                        }
                                    // Free result set
                                    mysqli_free_result($result);
                                } else{
                                    echo "</br></br><p><b><i>Ingen informationer fundet.</i></b></p>";
                                }
                            } else{
                                echo "ERROR: Was not able to execute $sql. " . mysqli_error($link);
                            }
                                                 echo "</tbody>";                            
                                    echo "</table>";
                            ?>
                            <p>
                                <div href="" class="button alt small" onclick="hideCreate()">OPRET NYT TILBUD</div>
                            </p>
                        </div>
 
                        <div id="create">    
                            <h4>1 - udfyld formularen</h4>
                                <form action="" method="post">
                                        <div class="6u 12u$(xsmall) <?php echo (!empty($car_err)) ? 'has-error' : ''; ?>">
                                            <label>Bil</label>
                                            <input type="text" name="car" class="6u 12u$(xsmall)" value="<?php echo $car; ?>">
                                            <span class="help-block"><?php echo $car_err;?></span>
                                        </div>
                                        <div class="6u 12u$(xsmall) <?php echo (!empty($user_err)) ? 'has-error' : ''; ?>">
                                            <label>Bruger</label>
                                            <input type="text" name="user" class="6u 12u$(xsmall)" value="<?php echo $user; ?>">
                                            <span class="help-block"><?php echo $user_err;?></span>
                                        </div>
                                            <input type="hidden" name="company" value="<?php echo $company; ?>">
                                            <input type="hidden" name="vat" value="<?php echo $vat; ?>">
                                            <input type="hidden" name="username" value="<?php echo $username; ?>">
                                            <input type="hidden" name="uniqid" value="<?php echo uniqid(); ?>" />
                                            <input type="hidden" name="status_request" value="AFVENTER TILBUD" />
                                            </br>

                                            <h4 class="pull-left">2 - vælg op til tre leasingselskaber</h4></br></br>
                                                <div class="table-wrapper">
                                                    <table class="table table-striped">
                                                        <thead>
                                                            <tr>
                                                                <th class="hidden"></th>
                                                                <th>Vælg</th>                                             
                                                                    <?php
                                                                        // Include config file
                                                                        require_once "assets/scripts/config.php";
                                                                        // Attempt select query execution
                                                                         $sql = "SELECT * FROM l_comp";
                                                                        if($result = mysqli_query($link, $sql)){
                                                                            if(mysqli_num_rows($result) > 0){
                                                          echo "<th>Leasingselskab</th>";                    
                                                      echo "</tr>";
                                                  echo "</thead>";
                                                  echo "<tbody>";
                                                                        while($row = mysqli_fetch_array($result)){
                                                          echo "<tr>";
                                                              echo "<th>";
                                                                  echo "<div class='6u 12u$(xsmall) <?php echo (!empty(" . $l_comp_err . ")) ? 'has-error' : ''; ?> 
                                                                        <input type='checkbox' id='" . $row['l_company'] . "' name='l_comps[]' <?php echo (in_array('l_comps', $var)?'checked':''); value='" . $row['l_company'] . "'?>
                                                                        <label for='" . $row['l_company'] . "'></label>
                                                                        <span class='help-block'><?php echo " . $l_comp_err. ";?></span>";
                                                              echo "</th>";                                            
                                                              echo "<th>" . $row['l_company'] . "</th>";
                                                          echo "</tr>";}
                                                                        // Free result set
                                                                        mysqli_free_result($result);
                                                                        } else{
                                                                        echo "</br></br><p><b><i>Ingen informationer fundet.</i></b></p>";
                                                                        }
                                                                        } else{
                                                                        echo "ERROR: Was not able to execute $sql. " . mysqli_error($link);
                                                                        }
                                                                        echo "</tbody>";                            
                                              echo "</table>";
                                                                        ?>

                                                                <input type="submit" class="button alt small" value="OPRET NYT TILBUD">
                                                                <a href="/offer_requests" class="button alt small">FORTRYD</a>

                                </form>
                        </div>
                    </div>
                </div>
            </div>

        <!-- Footer -->
            <footer id="footer" class="wrapper">
                <div class="inner">
                    <div class="copyright">
                        &copy; Fleets.dk - for virksomheder </br> 
                        <a href="mailto: kontakt@fleets.dk">KONTAKT OS</a> 
                    </div>
                </div>
            </footer>

        <!-- Scripts -->
            <script src="assets/js/jquery.min.js"></script>
            <script src="assets/js/jquery.scrolly.min.js"></script>
            <script src="assets/js/jquery.scrollex.min.js"></script>
            <script src="assets/js/skel.min.js"></script>
            <script src="assets/js/util.js"></script>
            <script src="assets/js/main.js"></script>
            <script src="assets/js/overlay_create.js"></script>
            <script src="assets/js/overlay_login.js"></script>

    </body>
</html>



Sending the value I selected with checkbox into ajax

When I use option select, I use the code;

var selNameGroup = document.getElementById("selectedNameGroup ");
selectedNameGroup = selNameGroup .options[selNameGroup .selectedIndex].text;
var docNameGroupIdId = selNameGroup .value;

and I pass into dynamic data.

if (selNameGroup != "" || selNameGroup !== "Choose Name Group") {
//NameGroupId is The request value returned from the model.
dynamicData["NameGroupId"] = docNameGroupIdId ;
  }

Likewise, how do I do for the checkbox?