JavaScript - getelementbyid null

 
Vista:

getelementbyid null

Publicado por rp27 (1 intervención) el 25/07/2019 21:52:22
Hola,
estoy intentando hacer que al enviar un formulario me redireccione a una web para que con los datos que se han insertado en el formulario se envié un mensaje de whatsapp personalizado, pero me devuelve valores nulos.
A ver mi me podéis ayudar.

El formulario:

1
2
3
4
5
6
7
8
9
10
11
<form action="pag.html" method="get" enctype="text/plain">
       <p>Nombre completo</p>
	<input name="name" type="text" id="nombre" size="30" maxlength="100">
	</br>
 
	<p>Regalo elegido</p>
	<textarea cols="50" rows="2" name="regalo" id="regalo"></textarea>
	<br>
 
	<input type="submit" value="Enviar">
</form>

El javascript:
1
2
3
4
5
6
7
8
function whatsapp(){
 
	var name = document.getElementById('nombre').value;
	var regalo = document.getElementById('regalo').value;
 
	return window.location = "https://api.whatsapp.com/send?phone=34615039722&text=Hola!%20Soy%20"+name+"%20y%20he%20elegido%20el%20regalo%20"+regalo+"%20:)";
 
}

La pagina donde se ejecuta el script:

1
2
3
4
5
6
7
8
9
10
<!DOCTYPE html>
<html lang="es">
	<head>
		<title>Redireccionando</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<script src="js/js.js"></script>
	</head>
	<body onload="whatsapp()">
	</body>
</html>


Espero que me podais ayudar, gracias.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

getelementbyid null

Publicado por stringIyan (20 intervenciones) el 25/07/2019 22:51:42
Buenas shur en el botón de enviar del formulario tienes que añadirle el parámetro onclick(WhatsApp())
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 26
Ha aumentado su posición en 7 puestos en JavaScript (en relación al último mes)
Gráfica de JavaScript

getelementbyid null

Publicado por stringIyan (20 intervenciones) el 25/07/2019 23:02:51
A ver shur, que antes estaba desde el móvil:

En el hmtl edita:
<input type="submit" value="Enviar">

y ponle un
1
<input type="submit" value="Enviar" onclick="whatsapp()">


Por que que yo sepa estas cargando el JS en el body, y no en el boton que es verdaderamente cuando das click. Prueba y me dices.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar