lundi 25 janvier 2021

Check if a Checkbox is checked?

In my Project i have this Checkbox

<g:CheckBox ui:field="answer"></g:CheckBox> <span class="{style.answer-font}">arithmetische Operatoren</span>

and this Button

<g:Button ui:field="abgabe" styleName="{style.button} bg-success text-white">ICH BIN FERTIG!</g:Button>

Now, when the User presses the button and the Checkbox is checked, then there will be a window-alert.

Button abgabe;
CheckBox answer;

@UiHandler("abgabe")
void check(ClickEvent e) {
    if (answer.isChecked()==true)
        Window.alert("HALLO");
}

But why it doesnt work?




dimanche 24 janvier 2021

woocommerce creating checkbox with multiple choises doesnt work [duplicate]

The following code uses a custom function woocommerce_wp_multi_checkbox() that I took from Multi checkbox fields in Woocommerce backend answer code.

It Should work just fine, because I already used that before and it worked without problems.

Here is my code attempt:

// Add custom multi-checkbox field for product general option settings
    add_action( 'woocommerce_product_options_general_product_data', 'add_custom_settings_fields', 20 );
    function add_custom_settings_fields() {
        global $post;
    
        echo '<div class="options_group hide_if_variable"">'; // Hidding in variable products
    
        woocommerce_wp_multi_checkbox( array(
            'id'    => '_custom_level',
            'name'  => '_custom_level[]',
            'label' => __('Levels', 'woocommerce'),
            'options' => array(
                'MBO'   => __( 'MBO', 'woocommerce' ),
                'HBO'   => __( 'HBO', 'woocommerce' ),
                'WO'    => __( 'WO', 'woocommerce' )
            )
        ) );
    
        echo '</div>';
    }
    
    // Save custom multi-checkbox fields to database when submitted in Backend (for all other product types)
    add_action( 'woocommerce_process_product_meta', 'save_product_options_custom_fields', 30, 1 );
    function save_product_options_custom_fields( $post_id ){
        if( isset( $_POST['_custom_level'] ) ){
            $post_data = $_POST['_custom_level'];
            // Data sanitization
            $sanitize_data = array();
            if( is_array($post_data) && sizeof($post_data) > 0 ){
                foreach( $post_data as $value ){
                    $sanitize_data[] = esc_attr( $value );
                }
            }
            update_post_meta( $post_id, '_custom_level', $sanitize_data );
        }
    }

My code wasn't working properly as I got this error:

Fatal error: Uncaught Error: Call to undefined function woocommerce_wp_multi_checkbox() in /home/wordcamp16870/www/vladi/wp-content/themes/astra-child/functions.php:609 Stack trace:
#0 /home/wordcamp16870/www/vladi/wp-includes/class-wp-hook.php(287): add_custom_settings_fields('') 
#1 /home/wordcamp16870/www/vladi/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters('', Array) 
#2 /home/wordcamp16870/www/vladi/wp-includes/plugin.php(484): WP_Hook->do_action(Array) 
#3 /home/wordcamp16870/www/vladi/wp-content/plugins/woocommerce/includes/admin/meta-boxes/views/html-product-data-general.php(186): do_action('woocommerce_pro...') 
#4 /home/wordcamp16870/www/vladi/wp-content/plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-data.php(42): include('/home/wordcamp1...') 
#5 /home/wordcamp16870/www/vladi/wp-content/plugins/woocommerce/includes/admin/meta-boxes/views/html-product-data-panel.php(51): WC_Meta_Box_Product_Data::output_tabs() 
#6 /home/wordcamp16870/www/vladi/wp-content/plugins/woocommerce/include in /home/wordcamp16870/www/vladi/wp-content/themes/astra-child/functions.php on line 609

Then I added missing woocommerce_wp_multi_checkbox() function code from the linked answer thread.

But now I get an error for in_array() where 2nd argument seems to be missing (see screenshot below):

enter image description here

I am student and I have this issues for first time.




Save the selected rows by checkbox and save it in database in php [closed]

I want to save data with selected checkbox with 4 different subject id in to different list(Phy, Chem, Math, Bio) with respective subject teacher. can anyone help me with thisJust refer the attach image




Save the selected rows by checkbox and save it in database in php

I want to save data with selected checkbox with 4 different subject id in to different list(Phy, Chem, Math, Bio) with respective subject teacher. can anyone help me with thisJust refer the attach image




samedi 23 janvier 2021

How to take multiple data at checkbox value in php?

Here I just grabbed the ID or a data in the check box. But I want to capture more data with the ID. How to do it?

<input type="checkbox" name="man" value="<?php echo $row['id']; ?>">

And how do I insert that data into another table via PHP MySQL?




How to get value from checkbox checked using javascript?

Why my javascript code didn't work? This output value is NaN.

javascript
for (var checkbox of markedCheckbox) {
    if(checkbox.checked){
      if(AI.includes(checkbox.id)){
        console.log("Flu Burung");
        document.getElementById("kesimpulan").hidden=false;
        document.getElementById("PE01").hidden=false;    
        document.getElementById("Solusi01").hidden=false; 

        //myBugs code
        for (var checkbox of markedCheckbox){
          if(AI.includes(checkbox.value)){
            y+=parseInt(checkbox.value);
          }
        }
        probabilitas = document.getElementById("probabilitas");
        probabilitas.innerHTML = (probabilitas.innerHTML.slice(0, -1) + y / 10 ) * 100;
      } else if {
    }
  }
}



how to get the ids of checked checkboxes in jquery

I want to get the ids of checked checkboxes and store those ids in an array using jquery. Can anybody give me correct code for it.

I have tried

Thanks in advance :)

$("#merge_button").click(function(event){
    event.preventDefault();
    var searchIDs = $("#find-table input:checkbox:checked").map(function(){
        return $(this).val();
    }).toArray();
    console.log(searchIDs);
});