views:

29

answers:

4

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.

+3  A: 

You'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/>");
Russ Cam
Many thanks Russ, it worked. I will let you know if I have any issues, thanks again.
newMe
A: 
document.write("<input type='button' value='" + ID + "' style='width:100;' />
Ian Wetherbee
Many thanks Ian, it worked.
newMe
+2  A: 

Alternatively, if you already have the button object written out, you can use the object model directly:

document.getElementById("idOfButtonObject").value = ID;
epicoxymoron
Many thanks EpicoxyMORON (nice sn), I did NOT have the button object. I will use this when needed.
newMe
A: 

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
Anurag
Many thanks Anurag, guess I will be ok with the document.write as of now. I will use the DOM method going forward.
newMe