You need to sign in to do that
Don't have an account?

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;
}
}
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;
}
}
Please see the sample code below
http://www.sfdcsharepoint.com/pass-values-page-controller/
Best Regards
Naga Kiran
This seems quite useful. Thanks. Let me try and get back.
Thanks
Priya