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
DJP1SDJP1S 

How can I enable a button once a selectList value is chosen?

I've got a select list with values in it, once something other than null or "--None--" is selected, I want a button to cease being disabled. How might this be accomplished, generally? Here's the chunk of code I'm working with:

 

                <b>&nbsp;IMC:&nbsp;</b>
                <apex:selectList value="{!selectedIMC}" multiselect="false" size="1" rerender="Search for CC Emails" >
                    <apex:selectOptions value="{!availableIMCs}"/>
                </apex:selectList>&nbsp;&nbsp;
    
                <b>Record Limit&nbsp;</b>
                <apex:inputText value="{!queryLimit}" required="false" style="width:30px;"/>&nbsp;&nbsp;
                
                <apex:commandButton value="Search for CC Emails" action="{!searchForClientCCs}" rerender="clientCCBlock, buttonBlock" status="ccSearchStatus" disabled="true"/>&nbsp;
                <apex:actionstatus id="ccSearchStatus">
                    <apex:facet name="start">
                        <div class="waitingSearchDiv" id="el_loading" style="background-color:#fbfbfb; height:100%; opacity:0.65; width:100%;"> 
                            <div class="waitingHolder" style="top: 84px; width: 91px;">
                                <img class="waitingImage" src="/img/loading.gif" title="Please Wait..." />
                                <span class="waitingDescription">Searching...</span>
                            </div>
                        </div>
                    </apex:facet>
                </apex:actionstatus>

 

I want Seach for CC Emails to enable when I click a value in IMC. Even a blog post overviewing the topic would be helpful. Thanks.

Saurabh DhobleSaurabh Dhoble

a. handle the onChange javascript event on the. apex:selectoption.

b. upon onChange, call a javascript that checks if the new value is other than none. if so, enable the button.

 

let me know if this works, if not i will get u the source code.

DJP1SDJP1S

Here's what I've tried but I can't seem to get it to work. The button stays enabled...

 

                <b>&nbsp;IMC:&nbsp;</b>
                <apex:selectList id="myList" value="{!selectedIMC}" multiselect="false" size="1" onSelect="!SetButtonStatus">
                    <apex:selectOptions value="{!availableIMCs}"/>
                </apex:selectList>&nbsp;&nbsp;
                
                <script language="javascript" type="text/javascript">
                function SetButtonStatus(myList, searchButton){
                    if(myList.value != null)
                    document.getElementById(searchButton).disabled = false;
                    else
                    document.getElementByID(searchButton).disabled = true;
                </script>
                
                <apex:commandButton id="searchButton" value="Search for CC Emails" action="{!searchForClientCCs}" rerender="clientCCBlock, buttonBlock" status="ccSearchStatus" />&nbsp;