+ Start a Discussion
muneeswar umuneeswar u 

validation using javascript on page block table in VF page

HIi can any one please solve my problem,Below I have placed the code
Thanks in advance,any support is appreciated.

<apex:page standardController="OpportunityLineItem" extensions="scheduleOptyProd" docType="html-5.0" sidebar="true" showHeader="true" standardStylesheets="true" cache="true">
    
    
    <script> 
    // JavaScript function to check the value entered in the inputField
    function validation() 
    {
        alert('test');
        var val = document.getElementById('{!$Component.fm.tabledata.pbl.pblt.qq}').value;
        alert('val:'val);
        if (val == null || val == '') 
        {
            alert('val is '+val);
        }
        else alert('Please enter some text');
        
    }
    </script>
    
    
    <apex:form id="fm" > 
        <apex:outputPanel rendered="{!recordsTable}"  id="tabledata">            
            <apex:sectionHeader subtitle="Edit Schedule for test {!oli.Product2.Name}"/>
            <p>Modify the schedule for this product. Click Recalculate to preview how your changes affect the total amount of the product. The total amount is the sum of the schedule installments. This total amount will override the amount stored on the product.
            </p>
            <apex:pageBlock id="pbl">  
 
                <!--VF Table starts here-->
                <apex:pageBlockTable value="{!lstWrapObj}" var="objWrap" id="pblt">             
                    <apex:column headerValue="Date">                     
                        <!--apex:input type="date" value="{!objWrap.wrapDate}"/-->                  
                        <apex:inputField value="{!objWrap.wrapOps.Start_Date__c}"/>
                    </apex:column>                  
                    <apex:column headerValue="Quantity" rendered="{!inputQuantityHide}" id="qc">   
                        <apex:inputText value="{!objWrap.Quantity}" rendered="{!inputQuantityHide}" id="qq" /> 
                        
                    </apex:column>  
                    
                    <apex:column headerValue="Revenue" rendered="{!inputRevenueHide}"> 
                        <apex:inputText value="{!objWrap.Revenue}" rendered="{!inputRevenueHide}"/>  
                    </apex:column>                
                    <apex:column headerValue="Comments">
                        <apex:inputText value="{!objWrap.Comments}" />                     
                    </apex:column>    
                    
                    <apex:column headerValue="Amount">
                        <apex:inputText value="{!objWrap.amount}" />                     
                    </apex:column>
                    
                </apex:pageBlockTable>  
                <!--VF Table ends here-->    
                
                <apex:pageBlockButtons >
                    <!--apex:commandButton value="Add Row" action="{!addRows}" reRender="all,tabledata,fm"/-->
                    <apex:commandButton value="Save" action="{!commitToDatabase}" /> 
                    <apex:commandButton value="Save & More" action="{!saveAndMore}" reRender="all,tabledata,fm" onclick="validation();" /> 
                    <apex:commandButton value="Cancel" action="{!tableCancel}" /> 
                </apex:pageBlockButtons>
            </apex:pageBlock>  
        </apex:outputPanel>
    </apex:form>
</apex:page>
Shaik Naga janiShaik Naga jani
Hi Muneeswar,
instead of checking the id use styleclass attribute in inputText, 
I updated the code check once it is working or not
<apex:page standardController="OpportunityLineItem" extensions="scheduleOptyProd" docType="html-5.0" sidebar="true" showHeader="true" standardStylesheets="true" cache="true">
    
    
    <script> 
    // JavaScript function to check the value entered in the inputField
    function validation() 
    {
        alert('test');
        var val = document.getElementsByClassName("iQuanity")[0].value;
        
        if (val) 
        {
            alert('val====> '+val);
        }
        else {
			alert('Please enter some text');
		}
        
    }
    </script>
    
    
    <apex:form id="fm" > 
        <apex:outputPanel rendered="{!recordsTable}"  id="tabledata">            
            <apex:sectionHeader subtitle="Edit Schedule for test {!oli.Product2.Name}"/>
            <p>Modify the schedule for this product. Click Recalculate to preview how your changes affect the total amount of the product. The total amount is the sum of the schedule installments. This total amount will override the amount stored on the product.
            </p>
            <apex:pageBlock id="pbl">  
 
                <!--VF Table starts here-->
                <apex:pageBlockTable value="{!lstWrapObj}" var="objWrap" id="pblt">             
                    <apex:column headerValue="Date">                     
                        <!--apex:input type="date" value="{!objWrap.wrapDate}"/-->                  
                        <apex:inputField value="{!objWrap.wrapOps.Start_Date__c}"/>
                    </apex:column>                  
                    <apex:column headerValue="Quantity" rendered="{!inputQuantityHide}" id="qc">   
                        <apex:inputText value="{!objWrap.Quantity}" rendered="{!inputQuantityHide}" id="qq" styleClass="iQuanity"/> 
                        
                    </apex:column>  
                    
                    <apex:column headerValue="Revenue" rendered="{!inputRevenueHide}"> 
                        <apex:inputText value="{!objWrap.Revenue}" rendered="{!inputRevenueHide}"/>  
                    </apex:column>                
                    <apex:column headerValue="Comments">
                        <apex:inputText value="{!objWrap.Comments}" />                     
                    </apex:column>    
                    
                    <apex:column headerValue="Amount">
                        <apex:inputText value="{!objWrap.amount}" />                     
                    </apex:column>
                    
                </apex:pageBlockTable>  
                <!--VF Table ends here-->    
                
                <apex:pageBlockButtons >
                    <!--apex:commandButton value="Add Row" action="{!addRows}" reRender="all,tabledata,fm"/-->
                    <apex:commandButton value="Save" action="{!commitToDatabase}" /> 
                    <apex:commandButton value="Save & More" action="{!saveAndMore}" reRender="all,tabledata,fm" onclick="validation();" /> 
                    <apex:commandButton value="Cancel" action="{!tableCancel}" /> 
                </apex:pageBlockButtons>
            </apex:pageBlock>  
        </apex:outputPanel>
    </apex:form>
</apex:page>
if it is helpful for please mark the best answer.
Thanks 
Shaik