[SalesForce] calling a javascript method to display a value on Output box by clicking apex command link

I am trying a scenario where on clicking a apex commandlink I need to capture a field's value and that value should be displayed on the same page in a seperate output text box or input text field.
"theDescription" field should be auto populated with the description selected when I click on the command link section.

Here is the code sample I used but some how its not working. Can you pls help?

<apex:inputField id="theDescription" required="true" value="{!strategy.Strategy_Description__c}" style="width:300px;height:100px;" />

<apex:commandLink id="linka" onclick="showData('{!$Component.linka}');" oncomplete="checkExistingDesc(); return false;" status="disableButtonForMultipleClicks" rerender="theDescription">{!a.Name}

function showData(id)
{
    var v = document.getElementById(id);
    alert ('Hi--------------------'+v);
}

Best Answer

Try this if it helps : It will give alert of value you have entered in the "theDescription" field.

    <apex:inputField id="theDescription" required="true" value="{!strategy.Strategy_Description__c}" style="width:300px;height:100px;" />

   <apex:commandLink id="linka" onclick="showData('{!$Component.linka}');" oncomplete="checkExistingDesc(); return false;" status="disableButtonForMultipleClicks" rerender="theDescription">{!a.Name}

     function showData()
     {
      var v = document.getElementById(theDescription);
      alert ('Hi--------------------'+v);
     }
Related Topic