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
Manish Verma 4Manish Verma 4 

Onclick java script funtion on custom button to update a field

my requirement is to create a button on opportunity which when clicked should update the stage to closed won.
Pls help!
Thanks
salesforce mesalesforce me
What I ended up doing was the following:
1)  In the controller - Add the Account ID to the picklist
//Add picklist to allow users to select the Account to run the Tool
    public SelectOption[] getIds() //https://www.interactiveties.com/blog/2009/visualforce-picklist.php#.U5Xin_ldXVF
    {
        SelectOption[] optionsList = new SelectOption[]{};        
		SelectOption[] options = new SelectOption[]{}; //new list for holding all of the picklist options       
		options.add(new selectOption(accountInstance.id, 'Account Number: '  + accountInstance.Customer_ID__c + ' - ' + accountInstance.name));
        options.add(new selectOption(accountInstance.id, 'TL Number: '  + accountInstance.TL_Number__c + ' - ' + accountInstance.TL_name__c));
        options.add(new selectOption(accountInstance.id, 'Uplink Number: '  + accountInstance.Uplink_Number__c + ' - ' + accountInstance.Uplink_name__c));
        options.add(new selectOption(accountInstance.id, 'WR Number: '  + accountInstance.Winning_Relationship_Number__c + ' - ' + accountInstance.Winning_Relationship__c));
		return options; //return the picklist options        
    }


2)  Delete the onclick Javascript
3)  Modify the Page ProductPenetrationPopUpPage to have the following picklist OnChange java script function. This function will redirect to the Run Tool url when changing the picklist selections on ProductPenetrationPopup page.
 
<apex:page standardController="Account" showChat="false" sidebar="false" showHeader="false" extensions="ProductPenetrationContExt" title="testing">   
<script type="text/javascript">
function chooseAccount(){
alert(document.getElementById('{!$Component.mainForm.mainBlock.mainSection.mainItem.listAccounts}').value);
window.open('/apex/ProductPenetration?id='+document.getElementById('{!$Component.mainForm.mainBlock.mainSection.mainItem.listAccounts}').value,'_parent');
}
</script>
    <apex:form id="mainForm"> 
          <apex:pageBlock >
                <apex:pageBlockSection >                       
                      <apex:outputField value="{!Account.Last_Sale_Date__c}" rendered="false"/>                     
                      <apex:outputField value="{!Account.name}"/>
                      <apex:outputField value="{!Account.Customer_ID__c}"/>       
                      <apex:outputField value="{!Account.Winning_Relationship_Number__c}"/>
                      <apex:outputField value="{!Account.Winning_Relationship__c}" rendered="false"/>
                      <apex:outputField value="{!Account.Uplink_Number__c}" rendered="false"/>
                      <apex:outputField value="{!Account.Uplink_Name__c}"/>
                      <apex:outputField value="{!Account.TL_Number__c}" rendered="false"/>
                      <apex:outputField value="{!Account.TL_Name__c}"/>
                      <apex:outputField value="{!Account.WA_Number__c}" rendered="false"/>
                      <apex:outputField value="{!Account.WA_Name__c}"/>
                </apex:pageBlockSection>
         </apex:pageBlock>        
         <apex:pageBlock id="mainBlock">
         <apex:pageBlockSection columns="1" id="mainSection">
                <apex:pageBlockSectionItem id="mainItem">
                    <apex:outputLabel value="Accounts" for="listAccounts"></apex:outputLabel>
                    <apex:selectList id="listAccounts" title="Accounts" size="1" multiselect="false" onchange="chooseAccount()">
                        <apex:selectOptions value="{!Ids}"></apex:selectOptions>
                    </apex:selectList>
                </apex:pageBlockSectionItem>
         </apex:pageBlockSection>
     </apex:pageBlock>
    </apex:form>   
</apex:page>