1

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.

4 Answers 4

5

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/>");
Sign up to request clarification or add additional context in comments.

1 Comment

Many thanks Russ, it worked. I will let you know if I have any issues, thanks again.
3

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

document.getElementById("idOfButtonObject").value = ID;

1 Comment

Many thanks EpicoxyMORON (nice sn), I did NOT have the button object. I will use this when needed.
0
document.write("<input type='button' value='" + ID + "' style='width:100;' />

Comments

0

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

1 Comment

Many thanks Anurag, guess I will be ok with the document.write as of now. I will use the DOM method going forward.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.