Hi everyone, I am trying to update the value which is stored in a particular part of my page by using the getElementsById method, followed by calling a function to update the field. However, I don’t know how to do this. The relevant parts of my code are as follows: function text(t) { return document.createTextNode(t); } function start(){ var oHelloText = text(getQuestion()); //the getQuestion method returns a string from an array oHelloText.id = "test"; } function updateDetails() { document.getElementById('test') = text(getQuestion()); } //sometime later, call to updateDetails method. Unsurprisingly, this doesn’t work. Any advice?
I think the part of the problem is this: document.getElementById('test') = text(getQuestion()); Code (markup): document.getElementById('test') is only the reference to an element. It sounds like you want to change the value of that element. So if 'test' is an input field, you would use this to change it: document.getElementById('test').value = "foobar"; Code (markup): It would change the contents of the input field to "foobar" for instance.
I think what you looking for is a document.getElementById('test').innerHTML = "Code to be input" Code (markup):
Ceck this part ,, here si problem var oHelloText = text(getQuestion()); //the getQuestion method returns a string from an array oHelloText.id = "test";