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
Shubham MirketaShubham Mirketa 

apex:selectlist sending blank to the bound controller varibale

I have a apex:selectList on my VF page and a controller variable is bound to it. But whenever i select anything in the list, it stores a blank in the  controller variable. I am facing this problem only when i run my page on Firefox or IE. It works fine in Chrome.
My selectList is as follows:
 <apex:selectList id="objectList" onchange="$('#err2').hide(); oOptVal=this.value;"  styleClass="select-menu" style="padding-left: 10px;" value="{!selectobject}" size="1" >     
          <apex:selectOption itemValue="None" itemLabel="Please select" />                   
          <apex:selectOption itemValue="Account" itemLabel="Account" />
          <apex:selectOption itemValue="Contact" itemLabel="Contact"/> 
          <apex:selectOption itemValue="Lead" itemLabel="Lead" />
  </apex:selectList>
The bound variable is also declared correctly,
public String selectobject{get;set;}

Still, it throws a blank value whenever anything is selected.
Can anyone help in fixing this? 
Thanks & Regards
Shubham Jha
Arun_KharbArun_Kharb
Hi Shubham,

You should initialize the variable in Constructor before referencing it.
like this:
selectObject = '';
 
Shubham MirketaShubham Mirketa
Hey Arun,

Thanks for the response. But i have initialised the variable in the constructor.
Arun_KharbArun_Kharb
Have you tried checking the rerender attributes in your code which might be resetting the values after postback?
Shubham MirketaShubham Mirketa
But then why does it work in chrome? And i have another selectList on the same page. There are no issues with that one either. Just this particular picklist. First the picklist was getting populated dynamically. I even tried hardcoding the values but nothing worked.
Arun_KharbArun_Kharb
Then there might be some javbascript issue which is not working on all browser. Do Check the Console in Developer tools of Chrome for any error which might be stopping your page to do the server side call.
Shubham MirketaShubham Mirketa
I have checked all the Javascript and all of it is working fine. The server side call is happening successfully as the debug is printing. Just the value of the bound variable is not getting as expected. Whenevr i set the debug, it shows " ".
Arun_KharbArun_Kharb
Can you please paste the complete source code, so that I can have a better look and might help you out.