0

Im constructing a visual force page in which im trying to display a message in <apex:outputLabel> thru javascript . How can i pass the value to the output label from javascript ,

  • Are you also using a control class? – jnoel10 Jul 25 '13 at 12:50
  • nope! no controller class – Aravind30790 Jul 25 '13 at 12:53
  • what outputs would you like ? can you give a small example by chance – jnoel10 Jul 25 '13 at 12:56
  • Just a text, based on the values in the url i got – Aravind30790 Jul 25 '13 at 12:58
3

you could do something like this:

//the outputlabel is rendered as a label element in html, you should fetch the id by inspecting the source of the page.
var myOutputLabel = document.getElementById('j_id0:outputText');
myOutputLabel.innerHTML='jhsdfsdfjksdnkf';

<apex:outputLabel id="outputText"></apex:outputLabel> 
  • perfect ! man u r awesome – Aravind30790 Jul 25 '13 at 13:16
  • 1
    And one question : won't the ID of the element get changed at anytime – Aravind30790 Jul 25 '13 at 13:18
  • it will depend on structure of your VF page. If you happen to alter (add / remove) any of the parent of this outputLabel element then yes the id gets changed, else it will remain the same. – Sam Jul 25 '13 at 13:20
  • thnx for the info – Aravind30790 Jul 25 '13 at 13:21
  • For that reason, I prefer to give apex elements a styleClass, then select using that class. The class name won't change, regardless of your page structure. Of course, it's more difficult to select an element by class name without a JS library like jQuery, but there are ways to do it, and it's much more stable (see: stackoverflow.com/questions/3808808/…) – Nathan Wallace Jul 25 '13 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.