I have been trying to figure out how I can remove a specific "li" tag by typing in its number based on its position in a list (i.e. type 3 in text box, then press a button to delete item in position 3 of the list). The way my code is now, even if there are only 4 items listed, typing in 5 and hitting enter still deletes 2 items rather than not deleting any. The way my code is written, it is not being consistent with the number being typed to delete the specific "li" tag.
Any help would be appreciated, thank you.
<html>
<head>
<title>Chapter 5 Activity</title>
</head>
<body>
<h1>The Best Fruit in the World</h1>
<ol id="fruit">
<li>Mangos</li>
<li>Watermelons</li>
<li>Kiwis</li>
<li>Pineapples</li>
</ol>
<form action="">
<input type="text" name="rfruit" id="fruitremove">
<input type="button" value="Click to Remove" onclick="removefruit()">
Remove fruit you dislike
</form>
<script type="text/javascript">
function removefruit(){
var fruitminus = document.getElementById("fruitremove").value;
var flist = document.getElementById("fruit");
flist.removeChild(flist.childNodes[fruitminus]);
}
</script>
</body>
</html>