+ Start a Discussion
anup ramanup ram 

Syntax error calling javascript with parameters in inputfield onblur

Hi,

 

I am getting syntax error while passing parameters to javascript from inputfield onblur attribute.

 

I do not know why the error is resulting in.

 

Please help me with the solution.

 

I hope there is no apex controller required along with the visualforce page.

 

VF CODE :

<apex:page standardController="Account" recordSetVar="accs" sidebar="false">

<script type="text/javascript">

 

  function computeTotal(quantityId, unitPriceId, totalId){

    var quantity = document.getElementById(quantityId).value;   

    var cost = document.getElementById(unitPriceId).innerHTML;       

    var totalPrice = quantity * cost;       

    document.getElementById(totalId).innerHTML = totalPrice;

  }

</script>

  <apex:form >

    <apex:pageBlock >

      <apex:pageBlockTable value="{!accs}" var="acc">

        <apex:column headerValue="Quantity">

         

                   <apex:inputText id="quantity" onblur="computeTotal('{!$Component.quantity}','{!$Component.unitPrice}','{!$Component.total}');"/>

 

        </apex:column>

        <apex:column headerValue="Unit Price">

          <apex:outputText id="unitPrice" value="10"/>

        </apex:column>

        <apex:column headerValue="Total Price">

          <apex:outputText id="total"/>

        </apex:column>

      </apex:pageBlockTable>

    </apex:pageBlock>

  </apex:form>

</apex:page>

Avidev9Avidev9
Try this give Id's to all the parent components of Quantity, unitPrice, total. Then try to refer them by doing something like this.

{!$Component.thePageId.theFormId.thePageblockId.the PageBlockTable.theColumnId.quantity}
VidulaVidula

Hi Anup, 

 

I have tried your code in my org, It's working fine in my org.