So basically I need to create a javascript validation where in It will check my <apex:inputfield>
. If it has the value of 0 it will throw a confirm with the field that is 0 and will ask the user if he wants to continue to save. Can someone help me please, been stuck with this one for days.
This is my VF Page
<apex:page Controller="editLineItemSPRCOMM" cache="false" tabstyle="Opportunity" action="{!initAfter}">
<script type="text/javascript">
function buttonValidate(){
}
</script>
<apex:form id="form1" >
<apex:pageBlock title="Line Item Calculator" id="aa">
<apex:pageMessages id="pmsg"/>
<apex:pageBlockButtons >
<apex:commandButton styleClass="butt1" value="Save and Return" action="{!saveLineItems}" onclick="buttonValidate()"/>
<!-- <apex:commandButton value="Refresh" action="{!refreshLineItems}"/> -->
</apex:pageBlockButtons>
<!-- Line Calculator for EMEA users -->
<apex:pageblockTable id="table2">
<!--apex:column headerValue="Recommended End User Discount %"-->
<apex:column headerValue="Rec. End User Disc %" id="ac">
<apex:inputField value="{!myVar.item.Rec_EndUser_Disc__c}" id="myNumber">
<apex:actionSupport event="onchange" action="{!calculateRecEndUserPrice}" status="counterStatus" rerender="table2,panel1,counterStatus,pmsg" id="aaa"/>
</apex:inputField>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
I already tried this two function just to try to check if the javascript is getting the values
function buttonValidate(){
alert(document.getElementById('{!$Component.form1.aa.table2.ac.myNumber}'));
}
returning null
function buttonValidate(){
alert(document.getElementById('{!$Component.form1.aa.table2.ac.myNumber}').value);
}
Not working it's just passing the alert and doing nothing
Can someone help me with this one been stuck for days.
{!$Component.form1.aa.table2.ac.myNumber}
. I believe it will also not work as the components are generated in loop and VF still does not support dynamic ID. – Saroj Bera Oct 28 '16 at 14:42