0
How to write input object array with for...loop in JavaScript?
3 Antworten
+ 3
var obj = { first: 'Hurong', last: 'Acoustic' };
var objArray =[];
objArray.push(obj);
+ 3
Javascript cannot access HTML code directly.
You can use
document.querySelectorAll('form input[type="text"')[i].value
to accees each input values.
Remember
input tags always come together in form tag.
You need a submit button at the end of all these input to submit the inputs to Javascript.
eg <input type="submit" onclick='submit(event)'>
in Javascript, add submit function:
function submit(e) {
e.preventDefault();
// add the get inputs code here
}
and please note that i iterator must be initialized to zero:
eg. for(i=0;i<3;i++)
+ 1
var arr=[];
for (i;i<3;i++){
arr.push(<input type='text'/>)};
why does my code is wrong?