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
natty dreadnatty dread 

jQuery .change event not working

I have a survey that I want to display based on the selection in a picklist. The survey branches depending on which option is selected. I'd like to use jQuery to hide and show the pertinent survey questions but the .change function doesn't seem to be doing anything. I just started messing around with jQuery yesterday so please be patient with me if I am missng something obvious. I'm at  a loss... Any help would be appreciated. 

 

(Note: I have tried using a jQuery static resource and it did not make any difference.)

 

the javascript

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.js" type="text/javascript"></script>
<script type="text/javascript"> $(document).ready(function(){ $('#theQuestions').hide(); $('#thePlan').change(function(){ if ($('#thePlan').val() == 'PPO') { $('#theQuestions').show(); $('#MAO').hide(); $('#DSNP').hide(); $('#CSNP').hide(); } }); }); </script>

 the visualforce

<div class="theFields">
   <p><apex:outputLabel >Type</apex:outputLabel></p>
   <apex:inputField value="{!c.Plan_Type__c}" id="thePlan" />
</div>

<div class="greybox" id="theQuestions"> 
  
   <div class="ques">
      <p>General Question?</p>
      <div class="selRad">
         <apex:selectRadio value="{!c.Question1__c}" >
	    <apex:selectOptions value="{!items}" />
	 </apex:selectRadio>
      </div>
   </div>
   <div class="ques" id="MAO">
      <p>MAO Question?</p>
      <div class="selRad">
         <apex:selectRadio value="{!c.Question2__c}" >
	    <apex:selectOptions value="{!items}" />
	 </apex:selectRadio>
      </div>
   </div>
   <div class="ques" id="PPO">
      <p>PPO Question?</p>
      <div class="selRad">
         <apex:selectRadio value="{!c.Question3__c}" >
	    <apex:selectOptions value="{!items}" />
	 </apex:selectRadio>
      </div>
   </div>
   <div class="ques" id="DSNP">
      <p>DSNP Question?</p>
      <div class="selRad">
         <apex:selectRadio value="{!c.Question4__c}" >
	    <apex:selectOptions value="{!items}" />
	 </apex:selectRadio>
      </div>
   </div>
   <div class="ques" id="CSNP">
      <p>CSNP Question?</p>
      <div class="selRad">
         <apex:selectRadio value="{!c.Question5__c}" >
	    <apex:selectOptions value="{!items}" />
	 </apex:selectRadio>
      </div>
   </div>

</div>

 

h8r41dh8r41d

The problem is that when you specify ID="whatever" on a VF element, you're specifying the ID that is accessible in VF, but not in HTML.

 

You'll notice that if you do an "inspect element" on the input, the DOM ID is not at all what you specified.

 

So, if you use jquery you have to use class selectors instead of IDs. Make your ThePlan input use styleClass="ThePlan" instead of ID= "ThePlan"

 

Then in your jquery code, use .ThePlan instead of #ThePlan

 

 

Gabriel Alack
Contact Us - We Can Help!
Salesforce Superheroes
------------------------------
help@salesforcesuperheroes.com
www.salesforcesuperheroes.com
1-888-407-9578 x122