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

0

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

But when loading from the base when doing the update page, I would like to load the page if the document type field is filled with "RG", and then activate the function to show the sender field.

I use this function to change the document type field, if you choose "RG", it shows the sender 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>
    
asked by anonymous 11.10.2018 / 12:10

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 questions are available!

    
11.10.2018 / 12:40