Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote