I have a form and when I run the event onclick
gives error, it says that the variable is not defined.
This is the button:
document.getElementById("btnSend").addEventListener("click", function myFunction() {
var first_name=document.getElementById("first_name").value.toUpperCase();
var last_name=document.getElementById("last_name").value.toUpperCase();
var cedula=document.getElementById("cedula").value.toUpperCase();
var ve=document.getElementById("ve").value;
var codigo=document.getElementById("codigo").value;
var phone=document.getElementById("phone").value;
var email=document.getElementById("email").value.toLowerCase();
var descripcion=document.getElementById("descripcion").value.toUpperCase();
if(first_name == null || first_name.length == 0 || /^\s+$/.test(first_name)){
swal("ERROR:", "El campo Nombre no debe ir vacío!");
return false;
}
if(cedula == null || cedula.length == 0 || isNaN(cedula)){
swal("ERROR:", "Debes ingresar su número de cedula");
return false;
}
if(codigo == null || codigo.length == 0 || isNaN(codigo)){
swal("ERROR:", "Debes ingresar el codigo del telefono");
return false;
}
if(phone == null || phone.length == 0 || isNaN(phone)){
swal("ERROR:", "Debes ingresar su número de telefono");
return false;
}
if(descripcion == null || descripcion.length == 0 || /^\s+$/.test(descripcion)){
swal("ERROR:", "Debes ingresar un Asunto");
return false;
}
var data = JSON.stringify({
"client_data": {
"id_doc": ""+ve+""+cedula+"",
"first_name": ""+first_name+"",
"last_name": ""+last_name+"",
"email": ""+email+"",
"phone": ""+codigo+""+phone+"",
},
"title": "PROSPECTO DE ALIADO",
"type": "REQUEST",
"weight": 1,
"channel": "WEB",
"description_markdown": ""+descripcion+"",
"time_estimate": 2400,
"business_id": "3606bce0-0d0c-11e8-bf0a-6b5a224d7afd"
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (xhr.readyState === 4) {
console.log(xhr.responseText);
var myObj = JSON.parse(this.responseText);
swal({
title: "¿Estás seguro?",
text: "Deseas enviar la solicitud ?",
icon: "warning",
buttons: true,
dangerMode: true,
})
.then((willDelete) => {
if (willDelete) {
swal("Solicitud enviada!", {
icon: "success",
text:" Su número de Ticket es : " +myObj.number,
title: "Enviado Exitosamente!",
});
}
});
}
});
xhr.open("POST", "https://api.paguetodo.com/issue/issue?user_id=3606bce0-0d0c-11e8-bf0a-6b5a224d7afd");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(data);
$(":text").each(function(){
$($(this)).val('');
});
});
<i>
<input type="submit" class="btn btn-default" value="Enviar" id="btnSend" onclick="myFunction();limpiarFormulario()"> </input></i>
<i>