Enable field when page loading if input is filled with specific word

Asked

Viewed 57 times

0

I have a registration form that when clicking on document type, if "RG" has a function in JS that shows a field that is defined in css as style="display: None".

However when loading from the base when doing on the update page you would like that when loading the page if the document type field is filled with "RG" ai activates the function to show the issuing field.

I use this function for when changing the document field, if you choose "RG" it shows the issuing field.

<script type="text/javascript" DEFER="DEFER">
  // INICIO FUNÇÃO DE MOSTRA ORGÃO EMISSOR
  window.onload=function(){
    document.getElementById('destypedoc').addEventListener('change', function () {
      var style = this.value == 'RG' ? 'block' : 'none';
      document.getElementById('hidden_div').style.display = style;
   });
 }
</script>

1 answer

0


Add this within the function window.onload:

var campoRG = document.getElementById('SEU_CAMPO_RG').value;
var display = campoRG.length > 0 ? 'block' : 'none';

document.getElementById('CAMPO_EMISSOR').style.display = display;

Any doubt I’m available!

  • Perfect worked very well thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.