Moeez
Moeez

Reputation: 478

Hide drop-down box on basis of text result using javascript

I want to hide a drop-down on the basis of a selected user input.

So far I have done

var getText = document.getElementById('issuemeters-issuance_type').value;

Then in if else condition

if(getText == 'HESCO/OEM')
         {
                $('.field-issuemeters-issuer').hide();// the drop-down which i want to hide
                $('#issuemeters-issuer').val('');// setting the text value to null
         }
         else 
         {
                $('.field-issuemeters-issuer').show();     
         }

It will work when getText is equal to HESCO/OEM. I have also checked the value in console but I don't know why it's not working.

Any help would be highly appreciated.

Upvotes: 0

Views: 31

Answers (1)

Roberto Bisello
Roberto Bisello

Reputation: 1235

try with a listener on "issuemeters-issuance_type" change:

$('#issuemeters-issuance_type').on('change',function(){
  if($(this).val() === 'HESCO/OEM')
         {
                $('.field-issuemeters-issuer').hide();// the drop-down which i want to hide
                $('#issuemeters-issuer').val('');// setting the text value to null
         }
         else 
         {
                $('.field-issuemeters-issuer').show();     
         }
});

assuming that "issuemeters-issuance_type"

Upvotes: 2

Related Questions