Soy un principiante en html y estaba tratando de aprender cómo funcionan los formularios en html, pero como se muestra en el siguiente código, no pude obtener los resultados del formulario después de hacer clic en el botón Enviar. ¿Puede decirme por qué no funciona y cómo solucionarlo?
índice.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>html/css</title> </head> <body> <form action="result.html" method="get"> <label for="N">Name:</label> <input type="text" id="N" name="Name" required> <br> <label for="P">Phone number:</label> <input type="number" id="P" name="phone_nos" required> <br> <button>submit</button> <br> </form> </body> </html>resultado.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <div id="results"></div> <a href="/">Go Back</a> <script> const resultsList = document.getElementById('results') new URLSearchParams(window.location.search).forEach( (value,name)=>{ resultsList.append('${name} : ${value}') resultsList.append(document.createElement('br')) }) </script> </body> </html>Esto es lo que se muestra en la pantalla después de hacer clic en el botón Enviar
${nombre} : ${valor} ${nombre} : ${valor}
Intente cambiar el método de formulario a POST en lugar de obtener
--> <form action="result.html" method="post">