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
Priyadarshini Manoharan 3Priyadarshini Manoharan 3 

How to pass a javascript variable from apex page to standard controller?

Here's the code, inputValue from apex page should be assigned to webcase.Product__c

Apex page

<apex:page standardController="Case" extensions="CaseStdControllerExt" title="Contact Us" showHeader="true" standardStylesheets="true" docType="html-5.0">


<apex:form id="frm">
    <apex:pageBlock title="Enter Case Details" rendered="true">
        <apex:pageBlockButtons >
        <apex:commandButton value="Submit Case" action="{!savecase}"/>
        </apex:pageBlockButtons>
        <apex:pageBlockSection title="Case Information" collapsible="false" columns="1">
        <apex:inputField value="{!Case.Product__c}"  id="inptID" onchange="MyjavaFunction('{!$Component.inptID}')" />
       
       

        <apex:inputField value="{!Case.Description}"  id="casedesc"/>
        </apex:PageBlockSection>
    </apex:pageBlock>
</apex:form>

 <!-- Java script starts Here -->
  <script>
   function MyjavaFunction(ReceiveInputID){
  
    var inputValue = document.getElementById(ReceiveInputID).value;
         if(inputValue == ''){
            alert('You did not eneter any value in input box');
         }
         else
         {
            alert(' You entered :: '+inputValue);
         }
           
           
   }
  </script>
</apex:page>

Standard Extension controller

public class CaseStdControllerExt {

private final Case webcase;

    public CaseStdControllerExt(ApexPages.StandardController controller) {
    
    webcase = (Case)controller.getRecord();

    }
    
     public PageReference savecase() 
     {
       

       upsert(webcase);
       PageReference p = new ApexPages.StandardController(webcase).view();
       p.setRedirect(true);
       return p;
       
     }

}

 
NagaNaga (Salesforce Developers) 
Hi Priyadarshini,

Please see the sample code below

User-added imagePlease see the link below for more information

http://www.sfdcsharepoint.com/pass-values-page-controller/

Best Regards
Naga Kiran
Priyadarshini Manoharan 3Priyadarshini Manoharan 3
Hi Naga,

This seems quite useful. Thanks. Let me try and get back.

Thanks
Priya