Peter
Peter

Reputation: 155

How to change h:outputText value by JavaScript?

I already tested with 2 inputText, It runs well for example

var tdate = document.getElementById('txtDate');    //h:inputText
var tdt = document.getElementById('txtDateTime');  //h:inputText

tdate.onchange = function(){
  tdt.value = tdate.value;
};

How can I change the value of " tdt " - h:outputText?

var tdate = document.getElementById('txtDate');    //h:inputText
var tdt = document.getElementById('txtDateTime');  //h:outputText

Upvotes: 6

Views: 16997

Answers (1)

BalusC
BalusC

Reputation: 1109532

Look in the generated HTML source. Rightclick page in browser and view source. You'll see that the <h:outputText> renders a HTML <span> element with the value in its body. To alter the body of a <span> in JavaScript you need to manipulate the innerHTML.

tdt.innerHTML = "new value";

Upvotes: 3

Related Questions