Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
193
rated 0 times [  194] [ 1]  / answers: 1 / hits: 7155  / 11 Years ago, mon, february 3, 2014, 12:00:00

I’m trying to make a form that looks like this:





where if inside of the input type =text is something like a number auto-check the CHECKBOX, is jquery? or simple PHP.



Ahh, the more important thing, I'm using woocommerce, so i make the function like that.



add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');


function my_custom_checkout_field( $checkout ) {




woocommerce_form_field( 'losung', array(
'type' => 'text',
'class' => array('my-field-class'),

'label' => __('titel'),
'placeholder' => __('Enter a number'),
), $checkout->get_value( 'my_field_name' ));
echo '<div class=spiele-container>';
echo '<input class=input-checkbox pull-left id= type=checkbox name=ter>';
echo '<div id=text-container-spiele>text ';
echo '</div>';
echo '</div>';

}

More From » php

 Answers
26

You can do something like this :



HTML :



<input type=text class=something />
<br>
<input type=checkbox name=check class=check>


JS:



$(input[type='text']).on(keyup, function(){
if(this.value!=){
$(input[type='checkbox']).prop(checked, checked);
}else{
$(input[type='checkbox']).prop('checked', );
}
});


Demo : http://jsbin.com/anANoSof/1/



Cleaner solution would be to use a class/id for the text-field as well as the checkbox and use like :



HTML :



<input type=text class=num />
<br>
<input type=checkbox name=check class=check>


JS:



$(.num).on(keyup, function(e){
if(this.value!=){
$(.check).prop(checked, checked);
}else{
$(.check).prop('checked', );
}
});


Demo : http://jsbin.com/iWESuTa/1/



As per @Fred, to disable the user from clicking the checkbox manually, simply use the disabled attribute as follows :



 <input type=checkbox disabled name=check class=check>


Demo : http://jsbin.com/iWESuTa/2/


[#48108] Sunday, February 2, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
daja

Total Points: 407
Total Questions: 103
Total Answers: 103

Location: Ghana
Member since Sun, Mar 27, 2022
2 Years ago
daja questions
Tue, Dec 21, 21, 00:00, 2 Years ago
Thu, Apr 23, 20, 00:00, 4 Years ago
Fri, Sep 6, 19, 00:00, 5 Years ago
Tue, Jul 23, 19, 00:00, 5 Years ago
;