Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

268
Visualizações
Cómo pasar el valor del formulario de una función a otra función y mostrar

Tengo tres archivos index.html,success.html e index.js y quiero validar el formulario en lugar de redirigir en consecuencia e imprimir los datos del formulario en la página de éxito. capaz de acceder a la variable de una función a otra Como código mi código aquí desde

 function check() { x = document.forms.myform.fname.value; if (x == "") { alert("First Name should be filled out!"); return false; } else { alert("Login Successful"); window.location.href = "success.html"; return false; } } // onload name function from success.html function name() { document.getElementById('fn').innerHTML = x; }
 <body> <h1>Welcome to Form Validation</h1> <form method="post" action="success.html" name="myform" onsubmit="return(check())"> <label>First Name</label> <input type="text" placeholder="First Name" name="fname"> <button type="submit">Submit</button> </form> <script src="./index.js"></script> </body>

exito.html

 function check() { x = document.forms.myform.fname.value; if (x == "") { alert("First Name should be filled out!"); return false; } else { alert("Login Successful"); window.location.href = "success.html"; return false; } } // onload name function from success.html function name() { document.getElementById('fn').innerHTML = x; }
 <head> <script src="./index.js"></script> </head> <body onload="name()"> <h1>Your form is submitted successfull.</h1> <p>Thanks</p> <div id="fn">Name Here</div> <hr width="50%"> </body>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

La forma más fácil de hacerlo sin tener un componente del lado del servidor es utilizar GET en lugar de POST en su formulario. Además, elimine la línea window.location: desea que el formulario se envíe de forma natural

 function check() { if (document.forms.myform.fname.value == "") { alert("First Name should be filled out!"); return false; } return true; } <form method="get" action="success.html" name="myform" onsubmit="return(check())"> <label>First Name</label> <input type="text" placeholder="First Name" name="fname"> <button type="submit">Submit</button> </form>

Y en la página de recepción acceda a la URL de la página con window.location.href ...

 var url_string = "http://www.example.com/success.html?fname=John"; //window.location.href var url = new URL(url_string); var c = url.searchParams.get("fname"); console.log(c);

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda