Note that there are some explanatory texts on larger screens.

plurals
  1. POGeneric function to hide an element when an input changes it value
    primarykey
    data
    text
    <p>Im new in this JavaScript world, but i have this problem i want to solve. I need to write a generic function in javaScript, so when someone fill the value of an inputText the attribute of the chekbox next to it change to 'inline', and if the value is deleted the attribute of the checkbox change to 'none'.</p> <p>Im using Primfaces 3, here is my code.</p> <pre><code>&lt;p:inputText id="inpValRezV" value="#{daniosParcialesBean.daniosParcialesDto.valorRezagoV}" onchange="hideCheckFromInput(this.value, 'chkValRezV');"/&gt; &lt;p:selectBooleanCheckbox widgetVar="chkValRezV" id="chkValRezV" value="#{daniosParcialesBean.daniosParcialesDto.mcaRezagoV}" /&gt; </code></pre> <p>And my javaScript code is:</p> <pre><code> function hideCheckFromInput(valueInput, idCheckBox){ var chkBox = document.getElementById(idCheckBox); if(valueInput == ''){ chkBox.style.display = 'none'; }else{ chkBox.style.display = 'inline'; } } </code></pre> <p>The last fragment of code doesn't works because getElementById is returning null!, however the next fragment works fine!</p> <pre><code> function hideCheckFromInput(valueInput, idCheckBox){ var chkBox = document.getElementById('principalDaniosTotales:documentacion:frmNegociacion:chkValRezV') if(valueInput == ''){ chkBox.style.display = 'none'; }else{ chkBox.style.display = 'inline'; } } </code></pre> <p>The problem is that i don't want to hardcode the full route of the checkbox, i'm trying to write a generic function to save lines of codes and reduce de javascript code.</p> <p>Thanks in advance! </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload