You need to sign in to do that
Don't have an account?
alexander yurpolsky
JavaScript in Visualforce Page
Hi. I am new to salesforce. I have to perform a simple task. When clicking an apex command button , it should alert a message through JavaScript with value from textbox "id=name" Please see my code.
But I am not getting expected response ("null"). Please help.
But I am not getting expected response ("null"). Please help.
<apex:page standardController="Campaign"> <apex:sectionHeader title="Campaign" subtitle="Campaign Edit"/> <script> function kk(){ var lol = document.getElementById('{!$Component.cam.title.bloc.theForm.name}'); alert(lol); } </script> <apex:form id="theForm"> <apex:pageBlock title="Campaign" mode="edit" id="title"> <apex:pageBlockButtons > <apex:commandButton onclick="kk();" value="TEST" /> <apex:commandButton action="{!save}" value="Save"/> <apex:commandButton action="{!cancel}" value="Cancel"/> <apex:commandButton value="Save & New" action="{!'save & new'}"/> </apex:pageBlockButtons> <apex:pageBlockSection title="My Content Section" columns="2" id="bloc"> <apex:inputfield value="{!Campaign.Campaign_Type__c}"> <apex:actionSupport event="onchange" reRender="theForm" /> </apex:inputField> <apex:inputtext value="{!Campaign.PPC__c}" rendered="{!Campaign.Campaign_Type__c == 'Campaign Type 1'}" /> <apex:inputText value="{!Campaign.name}" id="name" required="true" onchange="alertSample();"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
<apex:form id="theForm">
<apex:pageBlock title="Campaign" mode="edit" id="title">
<apex:pageBlockSection title="My Content Section" columns="2" id="bloc">
<apex:inputText value="{!Campaign.name}" id="name" required="true"onchange="alertSample();"/>
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_variables_global_component.htm
thank you for your response. I fixed the code. But now I get another message:
[object HTMLInputElement]
The previous message is correct but you want the value (so you must ask for it).