admin管理员组文章数量:1432632
Here i have written some code for getting values from dynamically created input box using javascript
Below is the Code for setting value:
for(var i=0;i<result.studentlist.length;i++){
var addtxt = document
.createElement("input");
addtxt.type = "text";
addtxt.name = "admissionno" ;
addtxt.id = "admissionno" ;
addtxt.value = result.studentlist[i].admissionno;
}
And getting purpose written below code:
var admissionNumber=document.getElementById("admissionno").value;
Actually two Admission numbers appended.
But, when am getting value at that time only first value is ing.
please give me an idea.
Here i have written some code for getting values from dynamically created input box using javascript
Below is the Code for setting value:
for(var i=0;i<result.studentlist.length;i++){
var addtxt = document
.createElement("input");
addtxt.type = "text";
addtxt.name = "admissionno" ;
addtxt.id = "admissionno" ;
addtxt.value = result.studentlist[i].admissionno;
}
And getting purpose written below code:
var admissionNumber=document.getElementById("admissionno").value;
Actually two Admission numbers appended.
But, when am getting value at that time only first value is ing.
please give me an idea.
Share Improve this question asked Apr 11, 2014 at 12:03 user2996174user2996174 1,4815 gold badges15 silver badges20 bronze badges 04 Answers
Reset to default 1document.getElementById("admissionno")
will always provide you a single element since ids are unique and the function also returns a single DOM element.
You should instead add classes and use them like document.getElementByClassName("classname")
. It will return you a Node List through which you can iterate over.
The parameter id must be unique. A solution will be:
Generation:
for(var i=0;i<result.studentlist.length;i++){
var addtxt = document.createElement("input");
addtxt.type = "text";
addtxt.name = "admissionno" ;
addtxt.id = "admissionno"+i ;
addtxt.value = result.studentlist[i].admissionno;
}
Collecting data (assuming you want to put all together):
var inputs=document.getElementsByName("admissionno");
var admissionNumber="";
for (var j=0;j<inputs.length;j++) {
admissionNumber+=inputs[j].value+" ";
}
I would put the input elements in a form to get multiple values at the same time. Also, if I am not mistaken you are creating duplicate id's with your code. What you want is:
document.getElementsByName("admissiono")
This method returns you an array of elements which can be iterated over. Or you can access certain positions with:
document.getElementsByName("admissiono")[0].value
HTML element id should be unique.I suppose that u should give the element different ids first.Then get each value of them.
本文标签: domHow to get values from dynamically created input box in javascriptStack Overflow
版权声明:本文标题:dom - How to get values from dynamically created input box in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745567087a2663826.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论