function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MBenfieldMBenfield 

Javascript to hide and reveal comments box

I wrote a simple script to display a comments box if 'Yes' is selected but it doesn't work... help?

script:

<script> function changeDisp(input, textid) { if(input == "Yes") document.getElementById(textid).style.display = "inline"; else document.getElementById(textid).style.display = "none"; } </script>

 

 

code:

<apex:PageBlockSection columns="1"> <apex:outputLabel value="Customer refused survey?" for="refused"/> <apex:InputField value="{!Post_Install_Survey__c.Refused__c}" id="refused" onChange="changeDisp(this,'{!$Component.rfcomments}');"/> <apex:outputPanel id="rfcomments"> <apex:InputField value="{!Post_Install_Survey__c.Refused_Comments__c}" style="display:none;"/> </apex:outputPanel> </apex:pageBlockSection>

 

           

 

Best Answer chosen by Admin (Salesforce Developers) 
dturkeldturkel

You getting that because you are passing the entire DOM object (i.e. "this"), and that obviously doesn't equal "Yes".  You need to pass the value of "this".... not sure the specific attribute -- could be "this.value" or "this.text".  Again, I'd suggest using Firebug to dtermine the right attribute name, or look it up in a Javascript reference for whatever control type is rendered..

 

David

All Answers

dturkeldturkel
Did you check to see what the actually value of "input" is when it comes into the function... try using Firebug, or simply put up an Alert box. Dave
MBenfieldMBenfield

I added an alert:

 

<script> function changeDisp(input, textid) { alert('The value of input is' + input); if(input == "Yes") document.getElementById(textid).style.display = "inline"; else document.getElementById(textid).style.display = "none"; } </script>

 The message I get when I call the function is: The value of input is[object HTMLSelectElement]

 

 

dturkeldturkel

You getting that because you are passing the entire DOM object (i.e. "this"), and that obviously doesn't equal "Yes".  You need to pass the value of "this".... not sure the specific attribute -- could be "this.value" or "this.text".  Again, I'd suggest using Firebug to dtermine the right attribute name, or look it up in a Javascript reference for whatever control type is rendered..

 

David

This was selected as the best answer
MBenfieldMBenfield
this.value did the trick, thanks Dave!