Last active
May 20, 2021 23:00
-
-
Save racmanuel/cdd8786009abd205ddce53c1695f5c84 to your computer and use it in GitHub Desktop.
Show or Hide a Select with jQuery and on load hold the field hide
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** Function to Show or Hide a field */ | |
function wcv_show_custom_field_time_warranty() | |
{ | |
?> | |
<script> | |
jQuery(function ($) { | |
if ($('#wcv_custom_product_warranty').val() == 'No') { //'.val()' | |
$("#wcv_custom_product_time_warranty").hide(); | |
$("label[for='wcv_custom_product_time_warranty']").hide(); | |
$('#wcv_custom_product_time_warranty').val(''); | |
} | |
$("#wcv_custom_product_warranty").change(function () { | |
var val = $(this).val(); | |
if (val === "Yes") { | |
$("#wcv_custom_product_time_warranty").show(); | |
} else if (val === "No") { | |
$("#wcv_custom_product_time_warranty").hide(); | |
$("label[for='wcv_custom_product_time_warranty']").hide(); | |
$('#wcv_custom_product_time_warranty').val(''); | |
} | |
}); | |
<?php | |
} | |
add_action('wp_footer', 'wcv_show_custom_field_time_warranty'); | |
?> | |
<!--Html file--> | |
<div class="control-group"> | |
<label for="wcv_custom_product_warranty">Warranty</label> | |
<div class="control select"> | |
<select id="wcv_custom_product_warranty" name="wcv_custom_product_warranty" class="select" style="" required="1"> | |
<option value="No" selected="selected">No</option> | |
<option value="Yes">Yes</option> | |
</select> | |
</div> | |
</div> | |
<div> | |
<div class="time-warranty all-100 small-100"><div class="control-group"> | |
<label for="wcv_custom_product_time_warranty" class="time-warranty all-100 small-100" style="display: none;">Product Time of Warranty</label> | |
<div class="control"> | |
<input type="number" class="" style="" name="wcv_custom_product_time_warranty" id="wcv_custom_product_time_warranty" value="" placeholder="Insert the Product Time of Warranty in Days"> | |
</div> | |
</div> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment