Add onChange to Select and change a value based on that and with reveal field
-
I need to change certain fields based on the selected item in the Select box selection in Woocommerce. Based on a selection it needs to change the post code and a selection from another Drop Down that has drop downs of Suburbs
I tried:
add_action( 'wp_head', function () { ?> <script> function onChangeFunc(){ var complex_name = document.getElementById('billing_selections').value; var suburb = document.getElementById('billing_suburb'); if complex_name == 'raslouwgardens' { document.getElementById("billing_suburb").value = suburb.options[complex_name.selectedIndex].text; document.getElementById("billing_postal").value = 1009; } } </script> <?php } );
With the element:
$fields['billing_estae'] = array( 'label' => __('Estate', 'woocommerce'), // Add custom field label 'placeholder' => _x('Estate', 'placeholder', 'woocommerce'), // Add custom field placeholder 'required' => false, // if field is required or not 'clear' => false, // add clear or not 'type' => 'select', 'options' => array( '' => 'Please select', 'gardens' => 'Gardens', 'tintle' => 'Tintle', 'other' => 'Other', ), 'class' => array('my-css'), 'priority' => 9,// );
A selection from here needs to change the post code however if they enter Other I need a text-box they can fill in (not sure where to add this and to leave it hidden unless Other is selected)
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Add onChange to Select and change a value based on that and with reveal field’ is closed to new replies.