admin管理员组文章数量:1332377
Hi im trying to get the number pushed into the array but cant seem to link the input to the array any help please
<html>
<body>
<form id="myform">
<input type="text" name="input">
<button onclick="myFunction()">Add number</button>
</form>
<br>
<div id="box" style="border:1px solid black;width:150px;height:150px;overflow:auto"></div>
<script>
var number= [];
function myFunction(){
number.push=("myform")
var x=document.getElementById("box");
x.innerHTML=number.join('<br/>');
}
</script>
</body>
</html>
Hi im trying to get the number pushed into the array but cant seem to link the input to the array any help please
<html>
<body>
<form id="myform">
<input type="text" name="input">
<button onclick="myFunction()">Add number</button>
</form>
<br>
<div id="box" style="border:1px solid black;width:150px;height:150px;overflow:auto"></div>
<script>
var number= [];
function myFunction(){
number.push=("myform")
var x=document.getElementById("box");
x.innerHTML=number.join('<br/>');
}
</script>
</body>
</html>
Share
Improve this question
edited May 4, 2023 at 18:02
RahulOnRails
6,54210 gold badges54 silver badges87 bronze badges
asked Sep 7, 2012 at 0:00
Linda wolfendenLinda wolfenden
1432 gold badges3 silver badges8 bronze badges
2 Answers
Reset to default 4You are assigning, when you should be calling. On top of that you are fetching the value wrong.
number.push(document.getElementById('myform')['input'].value);
You are adding the id of the form as a string. You have to add the value of the field, so that you can get it later:
var number= [];
function myFunction()
{
var input = document.getElementById('input');
number.push(input.value);
var x=document.getElementById("box");
x.innerHTML=number.join('<br/>');
}
本文标签: javascriptPush integer from Input to arrayStack Overflow
版权声明:本文标题:javascript - Push integer from Input to array - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742305777a2449884.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论