You need to sign in to do that
Don't have an account?
Javascript onclick
Hi team,
I am sharing snapshot of front and my apex class, visualforce page.
1.If i select checkbox and a value from picklist and click on save button i want to display the value of picklist in alertbox.
2.I have 2 pageblocksections, in that if the picklist values of 2 sections are Yes and corresponding checkbox is checked,i wantt a confirm dialog box saying do you want to proceed.
I dont want to make use of controller for adding logic to save button.
Thanks in advance. please help me out as i m learning i need some guidance in this to get good knowledge on javascript.
*************************************Apex class******************************************************
public class Movietable{
public List<Movie__c> mt{get;set;}
public List<Movie__c> mt1{get;set;}
public boolean b{get;set;}
public Movietable(ApexPages.standardController stdController) {
mt=[select id, Values__c,select__c,Cinemas__c from Movie__c];
mt1=[select id, Values__c,select__c,Cinemas__c from Movie__c where Cinemas__c='Bhajrangi Bhai jan'];
for ( Movie__c mves : mt) {
if(mves.Cinemas__c=='Bahubali')
{
system.debug('hello' +mves.Cinemas__c);
}
}
for ( Movie__c mves : mt1) {
if(mves.Cinemas__c=='Bhajrangi Bhai jan')
{
system.debug('hello1' +mves.Cinemas__c);
}
}
}
public PageReference save() {
return null;
}
}
<apex:page standardController="Movie__c" extensions="Movietable" id="p"> <apex:form id="f"> <apex:pageBlock title="Movie Table" id="pageblock" > <apex:commandButton action="{!save}" id="cb" value="Save" onclick="ss();"/> </apex:pageBlock> <apex:pageBlock id="pb1"> <apex:pageBlockSection id="pbs" title="1st group" collapsible="false"> <apex:dataTable id="dt" value="{!mt}" var="mlist" cellpadding="5" cellspacing="0" width="100%"> <apex:column id="c"> <apex:facet name="header"><center>Select to ADD</center></apex:facet> <apex:inputCheckbox value="{!mlist.select__c}" id="checkbox" > </apex:inputCheckbox> </apex:column> <apex:column > <apex:facet name="header"><center>Select value</center></apex:facet> <apex:inputField id="markForTermCheckbox1" value="{!mlist.Values__c}" /> </apex:column> </apex:dataTable> </apex:pageBlockSection> <apex:pageBlockSection id="pbs1" title="2nd group" collapsible="false"> <apex:dataTable id="dt" value="{!mt1}" var="mlist" cellpadding="5" cellspacing="0" width="100%"> <apex:column > <apex:facet name="header"><center>Select to ADD</center></apex:facet> <apex:inputCheckbox value="{!mlist.select__c}" id="checkbox1" > </apex:inputCheckbox> </apex:column> <apex:column > <apex:facet name="header"><center>Select value</center></apex:facet> <apex:inputField id="markForTermCheckbox2" value="{!mlist.Values__c}" /> </apex:column> </apex:dataTable> </apex:pageBlockSection> </apex:pageBlock> <script> function ss(){ alert("hi"); var chk=document.getElementById('{!$Component.checkbox}'); var val=document.getElementById('{!$Component.markForTermCheckbox1}'); alert("val" +val); alert("cvdgjhd" +chk); if(chk.value==true && val=='Yes') alert("chk" +chk.value); var a=document.getElementById('{!$Component.p.f.pageblock}').cb; alert("a" +a); } </script> </apex:form> </apex:page>
This can be achieved by java script,even i gone thru you description but i didn't understand your second question.
1) what is variable chk value, probably it wont give any value ,use var chk=document.getElementById('{!$Component.f.checkbox}').checked;
2) use ID's properly to get the values.
I have used id's only. I want to display a alertbox when the checkbox of a row is checked and picklist value as 'Yes' for 1st question
For 2nd question,i have 2 pageblocksection saying 1st group and 2nd group...both the pageblocksection select 'Yes' and if i click on Save..i need confirm dialog box