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

can someone help with html form and js switch case please <!DOCTYPE html> <html>

ID: 3706105 • Letter: C

Question

can someone help with html form and js switch case please

<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php" method="get">

First Name:<br>
<input type="text" name="first"><p>
Last Name<br>
<input type="text" name="last"><p>
Favorite Witch<br>

<input type="radio" name="Witch" value="Harry Potter"> Harry Potter<br>
<input type="radio" name="Witch" value="Hermione Granger"> Hermione Granger<br>
<input type="radio" name="Witch" value="Ron Weasley"> Ron Weasley
<p><input type="submit" value="witch?">
  

<p> Pick the witch you love</p>
<script>
var Witch = document.getElementById("radio").value;
switch (Witch) {
case 1:
Witch = "Harry potter";
break;
case 2:
Witch = "Hermione Granger";
break;
case 3:
Witch = "Ron Weasley";
break;

}
document.getElementById("radio").innerHTML = value;
}

</script>
</form>
</body>
</html>

Explanation / Answer

here you are using the form to submit the data to the action_page.php file...

hence whenever you clickk the submit button the form will be submitted to the action_page.php and the browser will be redirected to the action_page.php file.

hence you are not able to run the javascript instructions you written in the code.

if this file was named as action_page.php file..

That means if itself is the file action_page.php.

Then we have to collect the data forwarded to this page.

there are different ways to process the data which is recieved to a php file from another page's form.

for example :: <?php echo $_POST["name"]; ?> this line will print the data labled as "name" recieved from the other page's form.

hence the code you written is not printing anything on the webpage.