Skip to content

Instantly share code, notes, and snippets.

@kevotovar
Created December 17, 2018 14:14
Show Gist options
  • Save kevotovar/1e956d839f4932c402206f592f2640c1 to your computer and use it in GitHub Desktop.
Save kevotovar/1e956d839f4932c402206f592f2640c1 to your computer and use it in GitHub Desktop.
 $(document).ready(function() {
//funcion para iniciar campos de formularios
inicializarCampos = setInterval(function() {
if ($(".hs-form").length > 0) {
clearInterval(inicializarCampos);
$('input[name="trackid"]')
.val("utsnadlst")
.change();
//$('input[name="utm_source_custom"]').val(getUrlParameter('utm_source')).change();
//$('input[name="utm_medium_custom"]').val(getUrlParameter('utm_medium')).change();
//$('input[name="utm_campaign_custom"]').val(getUrlParameter('utm_campaign')).change();
}
});
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split("&"),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split("=");
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : sParameterName[1];
}
}
};
}); //cerramos funcion de document.ready
var regexOnlyLetters = /^[A-zÀ-ú]$/;
var regexOnlyDigits = /^[0-9]$/;
function maxLenghtInput(selector, maxLength) {
$(selector).atrr('maxLength', maxLength)
}
function onlyLettersInput(selector) {
$(selector).keypress(function (event) {
var keyValue = String.fromCharCode(event.which);
return regexOnlyLetters.test(keyValue);
});
}
function onlyDigitsInput(selector) {
$(selector).keypress(function (event) {
var keyValue = String.fromCharCode(event.which);
return regexOnlyDigits.test(keyValue);
});
}
function capitalizeInput(selector) {
$(selector).keypress(function (event) {
var value = event.target.value;
var capitalized = value.charAt(0).toUpperCase() + value.substring(1);
$(this).val(capitalized);
});
}
function minMaxLength(value, minLength, maxLength, callback) {
if(!(minLength > value.length && value.length <=maxLength)) {
callback()
}
}
//Validacion
window.onload = function(e) {
$("input[name=lastname], input[name=apellido_materno__c]").attr(
"disabled",
"disabled"
);
maxLenghtInput('input[name=firstname], input[name=lastname], input[name=apellido_materno__c]', 30);
maxLenghtInput('input[name=phone]', 10);
onlyLettersInput('input[name=firstname],input[name=segundo_nombre], input[name=lastname], input[name=apellido_materno__c]');
capitalizeInput('input[name=firstname],input[name=segundo_nombre], input[name=lastname], input[name=apellido_materno__c]');
onlyDigitsInput('input[name=phone]');
$("input").bind("cut copy paste", function(e) {
e.preventDefault();
});
$("select[name=campus_interes] option").each(function(index, element) {
if ($(this).text() == "001o000000etAAaAAM") {
$(this).text("Aguascalientes");
}
if ($(this).text() == "001o000000etBQkAAM") {
$(this).text("Chapultepec");
}
if ($(this).text() == "001o000000etAAxAAM") {
$(this).text("Chihuahua");
}
if ($(this).text() == "001o000000etAAyAAM") {
$(this).text("Coyoacan");
}
if ($(this).text() == "001o000000etAAVAA2") {
$(this).text("Cuernavaca");
}
if ($(this).text() == "001o000000etAAtAAM") {
$(this).text("Cumbres");
}
if ($(this).text() == "001o000000etAAnAAM") {
$(this).text("Guadalajara Norte");
}
if ($(this).text() == "001o000000etAAYAA2") {
$(this).text("Guadalajara Sur");
}
if ($(this).text() == "001o000000etAAbAAM") {
$(this).text("Hermosillo");
}
if ($(this).text() == "001o000000etAAhAAM") {
$(this).text("Hispano");
}
if ($(this).text() == "001o000000etAAkAAM") {
$(this).text("Lago De Guadalupe");
}
if ($(this).text() == "001o000000etAAcAAM") {
$(this).text("Lomas Verdes");
}
if ($(this).text() == "001o000000etAArAAM") {
$(this).text("Merida");
}
if ($(this).text() == "001o000000etAAXAA2") {
$(this).text("Mexicali");
}
if ($(this).text() == "001o000000etAAoAAM") {
$(this).text("Monterrey");
}
if ($(this).text() == "001o000000etAAqAAM") {
$(this).text("Nogales");
}
if ($(this).text() == "001o000000etAAUAA2") {
$(this).text("Puebla");
}
if ($(this).text() == "001o000000etAAZAA2") {
$(this).text("Queretaro");
}
if ($(this).text() == "001o000000etAAuAAM") {
$(this).text("Reynosa");
}
if ($(this).text() == "001o000000etAAiAAM") {
$(this).text("Roma");
}
if ($(this).text() == "001o000000etAAgAAM") {
$(this).text("Saltillo");
}
if ($(this).text() == "001o000000etAAWAA2") {
$(this).text("San Angel");
}
if ($(this).text() == "001o000000etAATAA2") {
$(this).text("San Luis Potosi");
}
if ($(this).text() == "001o000000etAASAA2") {
$(this).text("San Rafael");
}
if ($(this).text() == "001o000000etAApAAM") {
$(this).text("Santa Fe");
}
if ($(this).text() == "001o000000etAAwAAM") {
$(this).text("Tampico");
}
if ($(this).text() == "001o000000etAAdAAM") {
$(this).text("Texcoco");
}
if ($(this).text() == "001o000000etAAjAAM") {
$(this).text("Tlalpan");
}
if ($(this).text() == "001o000000etAAeAAM") {
$(this).text("Toluca");
}
if ($(this).text() == "001o000000etAAfAAM") {
$(this).text("Torreon");
}
if ($(this).text() == "001o000000etAAmAAM") {
$(this).text("Tuxtla");
}
if ($(this).text() == "001o000000etAAzAAM") {
$(this).text("Veracruz");
}
if ($(this).text() == "001o000000etAAvAAM") {
$(this).text("Victoria");
}
if ($(this).text() == "001o000000etAAlAAM") {
$(this).text("Villahermosa");
}
if ($(this).text() == "001o000000etAAsAAM") {
$(this).text("Zapopan");
}
});
/* ************************
Funciones por separado
************************* */
$("input[name=firstname]").focusout(function(event) {
//console.log('Paso por el blur 2');
var $nombre = $("input[name=firstname]").val();
var longitud = $nombre.length;
if (longitud < 3 || longitud > 30) {
alert("Error: el nombre debe tener de mas de 2 letras y menos de 30");
event.stopImmediatePropagation();
event.preventDefault(function() {
this.focus();
});
return false;
} else {
$("input[name=lastname], input[name=apellido_materno__c]").prop(
"disabled",
false
);
}
});
$("input[name=lastname]").focusout(function(event) {
//console.log('Paso por el blur 2');
var $nombre = $("input[name=lastname]").val();
var longitud = $nombre.length;
if (longitud < 3 || longitud > 30) {
alert(
"Error: el apellido Paterno debe tener de mas de 2 letras y menos de 30"
);
event.stopImmediatePropagation();
event.preventDefault(function() {
this.focus();
});
return true;
}
});
//FUNCION PARA NO REPETIR TECLA 3 VECES
function calc_numVecestexto(codigo, obj) {
if (obj.value.length == 0) {
keyAnt = codigo;
vecesText = 0;
return true;
} else if (keyAnt == codigo) {
if (vecesText >= 1) {
return false;
} else if (vecesText != 1) {
keyAnt = codigo;
vecesText = vecesText + 1;
return true;
}
} else {
if (keyAnt != codigo) {
keyAnt = codigo;
vecesText = 0;
return true;
}
}
}
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split("&"),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split("=");
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : sParameterName[1];
}
}
};
// asignar trackid de URL a la variable de sesion sessvars.trackid
if (getUrlParameter("trackid") != undefined) {
sessvars.trackid = getUrlParameter("trackid");
}
};
//cerramos window.onload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment