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 DeshmukhManish Deshmukh 

How to write a visualforce page to update field through javascript onclick of custom button

suriya deepaksuriya deepak
Hi manish ,

You can create custom button in object without go for visualforce page . and u can use javascript for that button  juz ill give small example to update field value using custom button (javascript button)

open oppurtunity obejct - Custom Button or Link - create new button - on click javascript option will be tere .!!!! after use below code to update field value while click that button.

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")} 

var newRecords = []; 

var c = new sforce.SObject("Opportunity"); 
c.id ="{!Opportunity.Id}"; 
c.CloseDate = new Date(); 
newRecords.push(c); 

result = sforce.connection.update(newRecords); 

window.location.reload();

regards
suriya.
PINKY REGHUPINKY REGHU
Hi,
            I have created  custom button on Account page
    In OnClick JavaScript    write this code:
                                                               window.location = 'apex/updatefield';
updatefield is the  name of vf page.
vf page:
<apex:page standardController="Account">
    <apex:PageBlock>
        <apex:PageBlockSection>
            <apex:form>
                Account name:<apex:inputField value="{!Account.Name}" />
                <apex:commandButton value="Save" action="{!save}" />
            </apex:form>
        </apex:PageBlockSection>
    </apex:PageBlock>
</apex:page>

Hope this helps.