So now I get a ',' seperator after every time I press submit on my input field which is linked to the myFunction function. I'd like to remove the ',' seperator. Because when I submit a name now it just prints a comma and adds another comma every time I press submit without filling out the input field.
var namenOSM = [];
var clubOSM = ["Wolves", "Derby", "Cardiff", "Aston villa", "Bristol City", "Sheffield utd", "Fulham", "Middlesbrough", "Brentford", "Leeds", "Preston", "Ibswich", "Norwich", "Nottingham", "Millwall", "QPR", "Sheffield Wed", "Redding", "Barnsley", "Bolton", "Hull city", "Sunderland", "Birmingham", "Burton"];
function myFunction() {
var newArray = document.getElementById("naam").value;
document.getElementById("naam").value = "";
namenOSM.push(newArray);
var clubRandom = Math.floor(Math.random() * clubOSM.length);
var node = document.createElement("LI");
var textnode = document.createTextNode(namenOSM + ' = ' + clubOSM[clubRandom]);
node.appendChild(textnode);
document.getElementById("namen").appendChild(node);
}
Player:<br>
<input id="naam" type="text" name="firstname" value="">
<br>
<br>
<input type="button" value="Submit" onclick="myFunction()">
<div id="namen">
</div>
I know the clubs are hardcoded into the array but it was a quick project for me to learn javascript a little.
Thanks!
` since you are using list items.