Create an external JS document that will remove a selected item from the list wh
ID: 3699124 • Letter: C
Question
Create an external JS document that will remove a selected item from the list when the button is pressed.
<!DOCTYPE html>
<html>
<head>
<title>Picking your Pets</title>
</head>
<body>
<p>Select which of the following pets you would not be able to keep:</p>
<form>
<select id="petOptions">
<option>Cat</option>
<option>Dog</option>
<option>Rat</option>
<option>Fish</option>
</select>
<input type="button" value="Select and Remove">
</form>
</body>
</html>
Explanation / Answer
<!DOCTYPE html>
<html>
<head>
<title>Picking your Pets</title>
<script>
function removePet() {
var x = document.getElementById("petOptions");
x.remove(x.selectedIndex);
}
</script>
</head>
<body>
<p>Select which of the following pets you would not be able to keep:</p>
<form>
<select id="petOptions">
<option>Cat</option>
<option>Dog</option>
<option>Rat</option>
<option>Fish</option>
</select>
<input type="button" value="Select and Remove">
</form>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.