0

Buenas lo que ocurre es que estoy tratando de obtener los datos de unos input text, date y time para modificar un mensaje personalizado que se le va a enviar por Whatsapp a cierta persona sin embargo el boton no me funciona simplemente no me redirecciona a la pagina con el mensaje personalizado como podria hacerlo?

Este es mi codigo :

<a onclick="wap();" id="Messa_wap" href="https://api.whatsapp.com/send?phone=34695685920&text=hola,%20¿qué%20tal%20estás?" class="boxed-btn submit-btn" value="click">Send Message</a>

Ese es el boton que envia el mensaje inicialmente sin embargo al hacer click no llama la funcion y se redirecciona inmediatamente a la pagina con el otro mensaje.

Esta es la funcion:

<script >
    function wap()
    {
        let nombre = document.getElementById("nam_t").value;
        let tel = document.getElementById("nam_p").value;
        let correo = document.getElementById("nam_em").value;
        let fecha = document.getElementById("nam_dat").value;
        let hor = document.getElementById("nam_ho").value;
        let mens = document.getElementById("nam_mess").value;

        document.getElementById("resultado").innerHTML= "<a id='Messa_wap' href='https://api.whatsapp.com/send?phone=1"+tel+"&text=Hi,%20"+nombre+"you%20have%20scheduled%20an%20appointment%20on%20"+fecha+"%20with%20the%20following%20instructions%20"+mens+"' class='boxed-btn submit-btn' value='click'>Send Message</a>";

    }


</script>

1 respuesta 1

0
    <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Static Template</title>
  </head>
  <body>
    <h1>formulario wtp</h1>
    <form id="frm">
      <input type="text" id="name" placeholder="Name" required />
      <input type="tel" id="phone" placeholder="Phone" required />
      <input type="email" id="email" placeholder="Email" required />
      <input type="date" id="date" required />
      <button type="submit">Enviar</button>
    </form>
  </body>
  <script src="./app.js"></script>
</html>




const frm = document.querySelector("#frm");

frm.addEventListener("submit", event => {
  event.preventDefault();
  const frm = event.target;
  const formData = {
    name: frm.name.value,
    phone: frm.phone.value,
    email: frm.email.value,
    date: frm.date.value
  };

  const URL = `https://api.whatsapp.com/send?phone=${formData.phone}&text=Hi, ${formData.name}%20you%20have%20scheduled%20an%20appointment%20on%20${formData.date}%20with%20the%20following%20instructions%20&source=&data=`;

  window.open(URL, "_blank");
});

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.