admin管理员组

文章数量:1317909

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

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
Share Improve this question edited Jun 1, 2012 at 4:35 BalusC 1.1m376 gold badges3.6k silver badges3.6k bronze badges asked Jun 1, 2012 at 4:18 PeterPeter 1552 gold badges2 silver badges8 bronze badges 3
  • 1 this link can be useful stackoverflow./questions/5654269/jsf-dynamically-change-form – Amit Commented Jun 1, 2012 at 4:25
  • Its the same way. Its not working for output text? – sgowd Commented Jun 1, 2012 at 4:26
  • yes, not working for output text – Peter Commented Jun 1, 2012 at 4:33
Add a ment  | 

1 Answer 1

Reset to default 3

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";

本文标签: jsfHow to change houtputText value by JavaScriptStack Overflow