You need to sign in to do that
Don't have an account?
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>
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
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]
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