JSFiddle - React, Tailwind, and code Playground
HTML
<form id="aggregateForm">
<input id="inputNum" value="" type="text"><input id="addnum" value="Add" onclick="add();" type="button">
<br>
<select id="selectBox" name="select" size="15" style="width:190px;">
</select>
<br>
<input id="calculate" value="Calculate" onclick="calculates();" type="button">
<input id="reset" value="Reset" onclick="reset();" type="button">
</form>
JavaScript
var selectbox = document.getElementById("selectBox");
function add() {
//Function to add a new number to the list of digits
//Parses an integer to ensure everything works okay
if (IsNumeric(document.getElementById("inputNum").value) == true) {
selectbox.options[selectbox.options.length] = new Option(document.getElementById("inputNum").value, document.getElementById("inputNum").value);
inputNum.focus();
}
else if (IsNumeric(document.getElementById("inputNum").value) == false) {
alert("I'm sorry, but you have entered an invalid number. Please enter a number into the input box.");
inputNum.focus();
}
}
//Calculate all numbers
var x = [];
function calculates() {
for (var i = 0; i < selectbox.options.length; i++) {
x[i] = selectbox.options[i].value;
alert(x[i]);
}
}
//IsNumeric function coding taken from http://stackoverflow.com/questions/18082/validate-numbers-in-javascript-isnumeric, code by Joel Coehoorn
function IsNumeric(input) {
return (input - 0) == input && input.length > 0;
}