+ Start a Discussion
Kate BrownKate Brown 

OnClick Java Script Button - If field equals x then update other field to a, else update other field to B

  I am working in a custom object and new to JavaScript. I want to create a button that basically says if a field equals "x" then update a different field to "A", if that field equals "y" then update the other field to "B", if the field is null then send an alert.

I got the button to work to update the field I need, but when I tried to create the if/then I got syntax errors.

Here is what I have so far:

{!REQUIRESCRIPT("/soap/ajax/27.0/connection.js")}
var objPrice_Quote__c = new sforce.SObject('Price_Quote__c');
objPrice_Quote__c.Id = '{!Price_Quote__c.Id}';
objPrice_Quote__c.Status__c = 'Customer Approval';
var result = sforce.connection.update([objPrice_Quote__c]);
location.reload(true);