+ Start a Discussion
arosysarosys 

Pass id in javacript function

I have a a java script requirement

 

I want to pass value to java script function like this :

This is my visual force page code:

 

<apex:dataTable value="{!products}" var="prod" >
<apex:column >
<apex:commandLink onclick="AddId({!prod.Id})" value="Add to Cart">
</apex:commandLink>
</apex:column>
</apex:dataTable>

 

function AddId(ProdId) {
alert(ProdId);
}

 

This is not working .

Please suggest how to pass it.

 

Best Answer chosen by Admin (Salesforce Developers) 
souvik9086souvik9086

Try like this

 

<apex:commandLink onclick="AddId('{!prod.Id}')" value="Add to Cart">

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

All Answers

souvik9086souvik9086

Try like this

 

<apex:commandLink onclick="AddId('{!prod.Id}')" value="Add to Cart">

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

This was selected as the best answer
Yoganand GadekarYoganand Gadekar

See if this example helps you out..

 

Using java script in visualforce page

 

Hit kudos and mark this as answer if it helps you.

 

Thanks,

asish1989asish1989

HI

Generally we  pass id like this only

<apex:inputText id="inptID"/>
                       <apex:commandButton onclick="MyjavaFunction('{!$Component.inptID}')" value=" Submit "/>

function MyjavaFunction(ReceiveInputID){
   
    var inputValue = document.getElementById(ReceiveInputID).value;

 

 

For your case

 I think you want id of column of datatble , In salesforce for that column Id is dynamically created, So you need to declare class in column and then get Id .

For example..

<apex:dataTable value="{!products}" var="prod" >
<apex:column  styleClass="showline">
       <apex:commandLink onclick="AddId(this)" value="Add to Cart">
       </apex:commandLink>
 </apex:column>
</apex:dataTable>

 

function AddId(ProdId) {

var menus  = document.getElementsByClassName("Teststyle");
alert(menus );


}

For your reference you can check this block

 

http://salesforceworld4u.blogspot.in/search/label/Disabling%20checkbox%20inside%20a%20pageblock%20table

 

If it helps you please give kudos and mark it as solution

 

Thanks