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
prasanth kumarprasanth kumar 

pageblock hide and show partially not working please help

i have two apex:pageblock in visualforce page.   1st pageblock will displays always. 2nd pageblock should be display with if condition,  but it is not working ...  please help. I checked this - data coming to javascript and alert boxes are working. 
 
<apex:page controller="myleaddata" id="p1">	
  <apex:form id="f1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
      <script>
       $j = jQuery.noConflict();

      var a;
      function mydata()
      {
          a=document.getElementById('p1:f1:pb:my1').value;
          document.getElementById('p1:f1:pb:my2').value=a;
          
      if(a=='New Employee')
          {
alert('this is 1st alert');
              j$(document).ready(function() {
   j$('div#hidden').show();
});
      
         }
else
{
alert('this is 2nd alert');
              j$(document).ready(function() {
   j$('div#hidden').hide();
});
      
         }
 }
      
      
      </script>
 
       <apex:pageblock title="Basic lead info" id="pb">
           <apex:outputlabel value="company name" />
        <apex:inputtext value="{!companyname}" /><br/>
        <apex:outputlabel value="lead last name" />
        <apex:inputtext value="{!lastname}" /><br/>
          <apex:outputlabel value="phone number" />
        <apex:inputtext value="{!phone}" /><br/>
          <apex:outputlabel value="Email" />
        <apex:inputtext value="{!email}" /><br/>
          <apex:outputlabel value="Source" />
        <apex:inputtext value="{!source}" /><br/>
          <apex:outputlabel value="Referer" />
        
           <apex:inputfield value="{!le.Reffered__c}" id="my1" onchange="mydata()" /><br/>
           <apex:inputhidden id="my2" value="{!referer}" />
    
    </apex:pageblock>
      <div id="hidden" >
          
     
      <apex:pageblock title="address info"  >
      
          <apex:outputlabel value="street" />
          <apex:inputtext value="{!street1}" /><br/>
          <apex:outputlabel value="city" />
          <apex:inputtext value="{!city1}" /><br/>
          <apex:outputlabel value="state" />
          <apex:inputtext value="{!state1}" /><br/>
          <apex:outputlabel value="zip" />
          <apex:inputtext value="{!zip1}" /><br/>
          <apex:outputlabel value="country" />
          <apex:inputtext value="{!country1}" /><br/>
          
      
      </apex:pageblock></div>
      
      <apex:commandButton value="submit" action="{!myleaddata1}" />
           </apex:form>
    
</apex:page>

Apex:code

public class myleaddata {
    public string lastname{set;get;}
    public string companyname{set;get;}
    public string leadname{set;get;}
    public string phone{set;get;}
    public string email{set;get;}
    public string  source {set;get;}
    public string referer{set;get;}
    public string street1{set;get;}
    public string city1{set;get;}
    public string state1{set;get;}
    public string zip1{set;get;}
    public string country1{set;get;}
   
    
    public lead le{set;get;}
    
     
    public void myleaddata1()
    {
    if(referer == 'existing employee')
    {
      Opportunity opp=new Opportunity();
        opp.Name=lastname;
       opp.StageName='qualification';
        opp.LeadSource=source;
        opp.CloseDate=date.parse('8/10/2015');
        insert opp;
        
      }
      
      else
      {
       lead l1=new lead();
        l1.lastname=lastname;
        l1.Company=companyname;
        l1.Phone=phone;
        l1.email=Email;
        l1.LeadSource=source;
        l1.Reffered__c=referer;
        
        // address info part
       l1.PostalCode=zip1;
       l1.Street  =street1; 
       l1.City=city1;
        l1.state=state1;
        l1.PostalCode=zip1;
        l1.Country=country1;
        
        insert l1;
       }
    }
}

 
Best Answer chosen by prasanth kumar
William TranWilliam Tran
Prasanth,

Try this for your apex page.

Thx
 
<apex:page controller="myleaddata" id="p1">	
  <apex:form id="f1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
      <script>
       $j = jQuery.noConflict();

      var a;
      function mydata()
      {
          a=document.getElementById('p1:f1:pb:my1').value;
          document.getElementById('p1:f1:pb:my2').value=a;
          
      if(a=='New Employee')
          {
alert('this is 1st alert');

     document.getElementById('hidden').style.display = 'block';
    
      
         }
else
{
alert('this is 2nd alert');

    document.getElementById('hidden').style.display = 'none';
 
      
         }
 }
      
      
      </script>
 
       <apex:pageblock title="Basic lead info" id="pb">
           <apex:outputlabel value="company name" />
        <apex:inputtext value="{!companyname}" /><br/>
        <apex:outputlabel value="lead last name" />
        <apex:inputtext value="{!lastname}" /><br/>
          <apex:outputlabel value="phone number" />
        <apex:inputtext value="{!phone}" /><br/>
          <apex:outputlabel value="Email" />
        <apex:inputtext value="{!email}" /><br/>
          <apex:outputlabel value="Source" />
        <apex:inputtext value="{!source}" /><br/>
          <apex:outputlabel value="Referer" />
        
           <apex:inputfield value="{!le.Reffered__c}" id="my1" onchange="mydata()" /><br/>
           <apex:inputhidden id="my2" value="{!referer}" />
    
    </apex:pageblock>
      <div id="hidden" >
          
     
      <apex:pageblock title="address info"  >
      
          <apex:outputlabel value="street" />
          <apex:inputtext value="{!street1}" /><br/>
          <apex:outputlabel value="city" />
          <apex:inputtext value="{!city1}" /><br/>
          <apex:outputlabel value="state" />
          <apex:inputtext value="{!state1}" /><br/>
          <apex:outputlabel value="zip" />
          <apex:inputtext value="{!zip1}" /><br/>
          <apex:outputlabel value="country" />
          <apex:inputtext value="{!country1}" /><br/>
          
      
      </apex:pageblock></div>
      
      <apex:commandButton value="submit" action="{!myleaddata1}" />
           </apex:form>
    
</apex:page>

 

All Answers

William TranWilliam Tran
Prasanth,

Try this for your apex page.

Thx
 
<apex:page controller="myleaddata" id="p1">	
  <apex:form id="f1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
      <script>
       $j = jQuery.noConflict();

      var a;
      function mydata()
      {
          a=document.getElementById('p1:f1:pb:my1').value;
          document.getElementById('p1:f1:pb:my2').value=a;
          
      if(a=='New Employee')
          {
alert('this is 1st alert');

     document.getElementById('hidden').style.display = 'block';
    
      
         }
else
{
alert('this is 2nd alert');

    document.getElementById('hidden').style.display = 'none';
 
      
         }
 }
      
      
      </script>
 
       <apex:pageblock title="Basic lead info" id="pb">
           <apex:outputlabel value="company name" />
        <apex:inputtext value="{!companyname}" /><br/>
        <apex:outputlabel value="lead last name" />
        <apex:inputtext value="{!lastname}" /><br/>
          <apex:outputlabel value="phone number" />
        <apex:inputtext value="{!phone}" /><br/>
          <apex:outputlabel value="Email" />
        <apex:inputtext value="{!email}" /><br/>
          <apex:outputlabel value="Source" />
        <apex:inputtext value="{!source}" /><br/>
          <apex:outputlabel value="Referer" />
        
           <apex:inputfield value="{!le.Reffered__c}" id="my1" onchange="mydata()" /><br/>
           <apex:inputhidden id="my2" value="{!referer}" />
    
    </apex:pageblock>
      <div id="hidden" >
          
     
      <apex:pageblock title="address info"  >
      
          <apex:outputlabel value="street" />
          <apex:inputtext value="{!street1}" /><br/>
          <apex:outputlabel value="city" />
          <apex:inputtext value="{!city1}" /><br/>
          <apex:outputlabel value="state" />
          <apex:inputtext value="{!state1}" /><br/>
          <apex:outputlabel value="zip" />
          <apex:inputtext value="{!zip1}" /><br/>
          <apex:outputlabel value="country" />
          <apex:inputtext value="{!country1}" /><br/>
          
      
      </apex:pageblock></div>
      
      <apex:commandButton value="submit" action="{!myleaddata1}" />
           </apex:form>
    
</apex:page>

 
This was selected as the best answer
Sunil PalSunil Pal
HI prasanth kumar

 
<script>
       $j = jQuery.noConflict();

      var a;
      function mydata()
      {
          a=document.getElementById('p1:f1:pb:my1').value;
          document.getElementById('p1:f1:pb:my2').value=a;
          
      if(a=='New Employee')
          {
            alert('this is 1st alert');
            
            j$('.divClass').show();
        
         }
        else
        {
            alert('this is 2nd alert');
                      j
           j$('.divClass').hide();

              
             }
         }
      
      
      </script>
      
      
      <div id="hidden" class='divClass'>

Try this and check one may be it will solve your issue.


Thanks
Sunil
prasanth kumarprasanth kumar
Thank you very much for the code.   thanks allot friends................ 
prasanth kumarprasanth kumar
hi William Tran.........       after using u r code, if intially i am able to enter data in all text boxes, if i select any value from dropdownlist then i am unable to enter data.  no text cusrsor is highliting in all fields .   please help.
prasanth kumarprasanth kumar
it is wokring in firefoc and not working in chrome.  please help
William TranWilliam Tran
What dropdown are you referring to?   Can you provide a screen print

Thx
prasanth kumarprasanth kumar
hi William Tran....  thank you very much for your code.   Actually its working, i thought it was not working because, if i click on text box with mouse then curor on text box not showing, but after that i tried to enter data after clicking, data is entering into text box which has been typed by me.  its just not showing cursor.  this is not a problem.   thanks you very much.