xml - variable as button value in javascript - Stack Overflow

I will be reading a tag from xml and assign it to a variable, ID.ID=(x[i].getElementsByTagName("ID

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 badges
Add a ment  | 

4 Answers 4

Reset to default 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/>");

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744381714a4571462.html

相关推荐

  • xml - variable as button value in javascript - Stack Overflow

    I will be reading a tag from xml and assign it to a variable, ID.ID=(x[i].getElementsByTagName("ID

    7天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信