Hi, I have a form in html and javascript that gives me the following error: Can not read property'value'of null and I do not know why I have attached the html and the js Html:
<form accept-charset="UTF-8" action="" method="post" onsubmit="enviaTelefonoNombre(); return false">
<h2></h2>
<div class="row">
<input class="span3" name="nombre" placeholder="nombre" type="text" id="nombrelp" required="" class="form-control podo-input" style="font-size:12px;height: 33px; margin-bottom: 0px; margin-top: 0px; text-align: center; width: 100%; background: white; border-radius: 20px; border: 1px solid #706f6f; min-width: 142px;margin-bottom:5%;">
<br>
</div>
<div class="row">
<input class="span3" name="telefono" placeholder="teléfono" type="tel" id="telefonolp" pattern="^(6|7|9)\d{8}" class="form-control podo-input" required="" style="font-size:12px;height: 33px; margin-bottom: 0px; margin-top: 0px; text-align: center; width: 100%; background: white; border-radius: 20px; border: 1px solid #706f6f; min-width: 142px;">
<br>
</div>
<input type="hidden" id="hiddenFormField" name="custId" value="nulo" style="float:left;padding: 4px 32px 4px 32px; margin: 0px; color: white; margin-right: 10px; background-image: linear-gradient(to right,#ff00b9, #ff0800); border-radius: 20px; border: 0; width: 100%; max-width: 150px; min-height: 33px;">
<br> <button class="boton" type="submit" style="float:left;padding: 4px 32px 4px 32px; margin: 0px; color: white; margin-right: 10px; background-image: linear-gradient(to right,#ff00b9, #ff0800); border-radius: 20px; border: 0; width: 100%; min-height: 33px;">Te llamamos</button>
<label><br><input name="acepto" type="checkbox" value="checkbox" required="" style="left:-10px;"> Acepto la<a href="/politica-de-privacidad/" name="submit" target=""_blank" type="submit" value="Enviar"> política de privacidad</a></label>
</form>
JS:
<script type="text/javascript">
function enviaTelefonoNombre(){
//Recuperación datos formulario
var phone=document.getElementById("telefonolp").value;
var name=document.getElementById("nombrelp").value;
var hidden=document.getElementById("hiddenFormField").value;
//var email=document.getElementById("email").value;
endpoint(phone,name,hidden,function(response){
console.log(response);
if(response===201) {
dataLayer.push({event:'calcula'});
alert("¡Gracias! Hemos recibido tu petición");
window.location.reload(false);
} else{
alert("Lo sentimos, no hemos podido procesar tu solicitud");
window.location.reload(false);
}
});
}
function endpoint(phone,name,hidden,callback4){
// Envío datos a callcenter
var data = "name=Afiliacion_web"+name+"&phone="+phone+"&source="+"&[email protected]"+hidden;
console.log(data);
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://backoffice.mipodo.com/api/contactforms/");
xhr.setRequestHeader("content-type", "application/x-www-form-urlencoded; charset=UTF-8");
xhr.setRequestHeader("accept", "*/*");
xhr.send(data);
xhr.onreadystatechange = function()
{
if (xhr.readyState == 4)
if(xhr.status == 200){
var response = xhr.responseText;
responseJsonOferta = JSON.parse(response);
//console.log('dentro: '+responseJsonOferta);
return callback4(responseJsonOferta);
}else {
return callback4(JSON.parse(xhr.status));
}
}
}
</script>