最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

xml - variable as button value in javascript - Stack Overflow

programmeradmin7浏览0评论

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
发布评论

评论列表(0)

  1. 暂无评论