File: /home/healthinsuranceapproval/public_html/assets/js/form.js
/*-- 1 --*/
$(document).ready(function () {
$(".check-free").click(function () {
$("#free").prop("checked", true);
});
$(".check-premium").click(function () {
$("#premium").prop("checked", true);
});
$(".reset").click(function () {
$("#free").prop("checked", false);
$("#premium").prop("checked", false);
});
});
/*-- 2 --*/
window.onload=function()
{
//document.getElementById('url').value = window.location.href
};
/*-- 3 --*/
//function for radio buttons
function addCheckAttribute(){
let val = 0;
$("input[name='radio-price']").click(function(){
let prevVal = val;
val = $("input[name='radio-price']:checked").val();
if ( val !== prevVal) {
$(this).attr('checked', true);
$(`input[value=${prevVal}]`).attr('checked', false);
}
});
}
/*-- 4 --*/
/*-----------------------------------------------------------------------*/
/*--------------------------- Date of Birth ----------------------------*/
/*-----------------------------------------------------------------------*/
$(document).ready(function() {
$.getJSON('https://api.ipify.org?format=jsonp&callback=?', function(data) {
$('#IpAddress').val(data.ip);
});
$.dobPicker({
daySelector: '#dobday', /* Required */
monthSelector: '#dobmonth', /* Required */
yearSelector: '#dobyear', /* Required */
dayDefault: 'Day', /* Optional */
monthDefault: 'Month', /* Optional */
yearDefault: 'Year', /* Optional */
minimumAge: 18, /* Optional */
maximumAge: 100 /* Optional */
});
});
$('#dobmonth').change(function(){
$('#dob').val($('#dobmonth').val() + '-' + $('#dobday').val() + '-' + $('#dobyear').val()); });
$('#dobday').change(function(){
$('#dob').val($('#dobmonth').val() + '-' + $('#dobday').val() + '-' + $('#dobyear').val());
});
$('#dobyear').change(function(){
$('#dob').val($('#dobmonth').val() + '-' + $('#dobday').val() + '-' + $('#dobyear').val());
});
/*-----------------------------------------------------------------------*/
/*---------------------------- Post Lead --------------------------------*/
/*-----------------------------------------------------------------------*/
/*-- 5 --*/
//jQuery time
var current_fs, next_fs, previous_fs; //fieldsets
var left, opacity, scale; //fieldset properties which we will animate
var animating; //flag to prevent quick multi-click glitches
$("#nextTest").click(function(){
if(animating) return false;
animating = true;
current_fs = $(this).parent();
next_fs = $(this).parent().next();
//activate next step on progressbar using the index of next_fs
$("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
//show the next fieldset
next_fs.show();
//hide the current fieldset with style
current_fs.animate({opacity: 0}, {
step: function(now, mx) {
//as the opacity of current_fs reduces to 0 - stored in "now"
//1. scale current_fs down to 80%
scale = 1 - (1 - now) * 0.2;
//2. bring next_fs from the right(50%)
left = (now * 50)+"%";
//3. increase opacity of next_fs to 1 as it moves in
opacity = 1 - now;
current_fs.css({
'transform': 'scale('+scale+')',
'position': 'absolute'
});
next_fs.css({'left': left, 'opacity': opacity});
},
duration: 800,
complete: function(){
current_fs.hide();
animating = false;
},
//this comes from the custom easing plugin
easing: 'easeInOutBack'
});
})
$(".next").click(function() {
console.log('123');
if (animating) return false;
animating = true;
current_fs = $(this).parent();
next_fs = $(this).parent().next();
//activate next step on progressbar using the index of next_fs
$("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
//show the next fieldset
next_fs.show();
//hide the current fieldset with style
current_fs.animate({
opacity: 0
}, {
step: function(now, mx) {
//as the opacity of current_fs reduces to 0 - stored in "now"
//1. scale current_fs down to 80%
scale = 1 - (1 - now) * 0.2;
//2. bring next_fs from the right(50%)
left = (now * 50) + "%";
//3. increase opacity of next_fs to 1 as it moves in
opacity = 1 - now;
current_fs.css({
'transform': 'scale(' + scale + ')',
'position': 'absolute'
});
next_fs.css({
'left': left,
'opacity': opacity
});
},
duration: 600,
complete: function() {
current_fs.hide();
animating = false;
},
//this comes from the custom easing plugin
easing: 'easeInOutBack'
});
});
$(".previous").click(function() {
if (animating) return false;
animating = true;
current_fs = $(this).parent();
previous_fs = $(this).parent().prev();
//de-activate current step on progressbar
$("#progressbar li").eq($("fieldset").index(current_fs)).removeClass("active");
//show the previous fieldset
previous_fs.show();
//hide the current fieldset with style
current_fs.animate({
opacity: 0
}, {
step: function(now, mx) {
//as the opacity of current_fs reduces to 0 - stored in "now"
//1. scale previous_fs from 80% to 100%
scale = 0.8 + (1 - now) * 0.2;
//2. take current_fs to the right(50%) - from 0%
left = ((1 - now) * 50) + "%";
//3. increase opacity of previous_fs to 1 as it moves in
opacity = 1 - now;
current_fs.css({
'left': left
});
previous_fs.css({
'transform': 'scale(' + scale + ')',
'opacity': opacity
});
},
duration: 600,
complete: function() {
current_fs.hide();
animating = false;
},
//this comes from the custom easing plugin
easing: 'easeInOutBack'
});
});
$(".submitButton").click(function() {
return false;
});
/*-- 6 --*/
/*-----------------------------------------------------------------------*/
/*------------------------------ PHONE NUMBER POST ------------------------------*/
/*-----------------------------------------------------------------------*/
$('#phone').keyup(function () {
this.value = this.value.replace(/[^0-9\.]/g,'');
});
/*-- 7 --*/
/*-----------------------------------------------------------------------*/
/*------------------------------ DATA POST ------------------------------*/
/*-----------------------------------------------------------------------*/
function submitForm() {
$('#submitButton').prop('disabled', true);
var url = window.location.href;
$.ajax({
type: 'post',
dataType: 'jsonp',
url: 'https://ushaleads.healthinsuranceguide.org/api/LeadAPI',
data: $('form').serialize(),
success: function() {
console.log('success');
window.location.href = "./form-success.php";
},
error: function() {
console.log('Error');
window.location.href = "./form-success.php";
}
});
}
/*-- 8 --*/
/*-----------------------------------------------------------------------*/
/*---------------------------- Zip Code Lookup --------------------------*/
/*-----------------------------------------------------------------------*/
$('#zipCode').on("input", function() {
var zipCode = $('#zipCode').val();
if (zipCode.length == 5) {
$.ajax({
type: 'GET',
url: 'https://ziplookup.visualyzers.com/Ziplookup?zipcode=' + zipCode,
success: function(results) {
if (!results) {
$('#errorZip').show();
$('#submitButton').prop("disabled", true);
} else {
$('#city').val(results.city);
$('#state').val(results.state);
$('#errorZip').hide();
$('#submitButton').prop("disabled", false);
}
}
});
}
});
/*-- 9 --*/
/*-----------------------------------------------------------------------*/
/*---------------------------- jQuery Validation ------------------------*/
/*-----------------------------------------------------------------------*/
$("#msform").submit(function(e) {
e.preventDefault();
}).validate({
rules: {
phone: {
required:true,
minlength:10,
maxlength:10,
},
firstname: {
required: true
},
lastname: {
required: true
},
email: {
required: true,
email: true
},
city: {
required: true
},
state: {
required: true
},
zipCode: {
required: true,
minlength: 5,
maxlength: 5
}
},
messages: {
phone: {
required: "Please enter a valid phone number"
},
},
submitHandler: function(event) {
submitForm();
}
});