I have a page containing a lots of text boxes with an incremental id. I'd like to read all these IDs and display them using javascript.
HTML page that looks like:
<input type="text" id="item1" value="111" ></input>
<input type="text" id="item2" value="222" ></input>
<input type="text" id="item3" value="333" ></input>
and a javascript part:
for (var i=1; i<3; i++){
var values = parseInt(document.getElementById('item' + i).value);
document.write(values);
}
I can't figure out why but only the first ID is displayed then firefox return an error (in the debugging console sysing: TypeError: document.getElementById(...) is null
Thanks for your help !
Romain
for(var i=1; i<3; i++)will write only 2 elementsdocument.write()obliterates the entire page when it's called after the page has completed.document.write()is used on a document that is already loaded, it clears the current document and starts a new blank one, thus wiping out your current DOM. Chance are you don't want to usedocument.write()here at all.