How to read a drop-down value on a custom form in Javascript?
Publication le 20 mars 2024
I'm trying to hide the Attachments options on a custom request form in Guide when a custom field dropdown is set to No, and leave the Attachments fields alone when it's set to Yes or not set. I've got the JS code to hide the Attachments bits, but I can't for the life of me figure out the correct if statement.
Fair warning, I'm not really familiar with JS, but I'm not new to coding. I've tried variations on the following, with no luck.:
if (document.querySelector('.request_custom_fields_24800067478036').value= "[custom field tag or custom field value]")
and
if ($('.request_custom_fields_24800067478036').value= "[custom field tag or custom field value]")
Any help is appreciated.
EDIT: I was able to find someone doing something similar, and found code that lead to this. Ideally I'd only need the first if, but looks like if they change between the two options, unless I have the second if the attachments won't come back. If anyone knows a better way to do this, please let me know, but this is working now.
$('#request_custom_fields_24800067478036').change(function(){
if ($(this).attr('value') == 'ecno_vetted_no') {
$('label[for=request-attachments]').hide();
$('#upload-dropzone').hide();
}
});
$('#request_custom_fields_24800067478036').change(function(){
if ($(this).attr('value') == 'ecno_vetted_yes') {
$('label[for=request-attachments]').show();
$('#upload-dropzone').show();
}
});
0
3 commentaire
Vous connecter pour laisser un commentaire.