I will be reading a tag from xml and assign it to a variable, ID.
ID=(x[i].getElementsByTagName("ID-NUM")[0].childNodes[0].nodeValue);
How could I use the variable, ID, as the button value to display?
document.write("<input type = button value = ID style='width:100'><br><br>");
Kindly let me know if I an not clear, thanks.
I will be reading a tag from xml and assign it to a variable, ID.
ID=(x[i].getElementsByTagName("ID-NUM")[0].childNodes[0].nodeValue);
How could I use the variable, ID, as the button value to display?
document.write("<input type = button value = ID style='width:100'><br><br>");
Kindly let me know if I an not clear, thanks.
Share Improve this question asked Jul 15, 2010 at 19:21 newMenewMe 481 silver badge4 bronze badges4 Answers
Reset to default 5You'll need to put that variable into the string that you're writing out
document.write("<input type='button' value='" + ID + "' style='width:100%'/><br/><br/>");
Alternatively, if you already have the button object written out, you can use the object model directly:
document.getElementById("idOfButtonObject").value = ID;
document.write("<input type='button' value='" + ID + "' style='width:100;' />
Don't use document.write
to insert anything on the page. It's problematic because if you do it after the object model has been constructed, it will wipe out the entire document and create a new one. Instead use the DOM methods to create a button.
var input = document.createElement('input');
input.type = 'button';
input.value = ID; // set the ID
input.style = 'width: 100';
document.body.appendChild(input); // add to page