In this post we are covering 5 points points:-

  1. How to call api in select box
  2. How to get values from Api values by selecting first dropdown to second dropdown Values —– https://jsfiddle.net/superbwebdeveloper/6z1vwetx/10/
  3. Form jQuery Validation
  4. After Selecting Select dropdown the color of the selected value changed, not the whole select box color
  5. How to add Tooltip Validation
status	
code	200
message	"Success"
data	
CA	
0	"San Francisco"
1	"Half Moon Bay"
2	"Los Angeles"
3	"South San Francisco"
4	"San Diego"
BC	
0	"Vancouver"
DE	
0	"Dover"
CO	
0	"Thornton"
TX	
0	"Fort Worth"
Arizona	[]
WV	
0	"Buckhannon"
error	{}


<script>
let xanoUrl = new URL(APIURL);
 var listall = {};
 
function getStates() {
  let request = new XMLHttpRequest();
  let url = xanoUrl.toString();
  request.open('GET', url, true);
    request.onload = function() {
     
      let getdata = JSON.parse(this.response);
            if (request.status >= 200 && request.status < 400) {  
             $.each(getdata.data, function (i, dropdown1) {                  
                    if (dropdown1.length===0) {              
                    }
                    else {
                     listall[i] = dropdown1; 
                    }
             }); 
             $.each(listall, function(key,value){   
            
             var option = jQuery('<option />');
                        option.attr('value', key).text(key);
                        jQuery('#state-list').append(option); 
                        
            var option2 = jQuery('<option />');
                        option2.attr('value', key).text(key);
                        jQuery('#state-list2').append(option2); 
                        
            });             
        }      
    } 
     
    request.send();
    
}
function getAreas(state,formnum) {   
        jQuery.each( listall[state], function( key, value ) {
            var arealist = jQuery('<option />');
            arealist.attr('value', value).text(value);
            if(formnum=="1"){
            	jQuery('#area-list').append(arealist); 
            }
            else{
            	jQuery('#area-list2').append(arealist); 
            }
        });
}

(function() {
    getStates();
    
     jQuery("#state-list").on("change", function(ev) {             
             jQuery('#area-list').children('option:not(:first)').remove();
   
              var cityId = jQuery("option:selected", this).val();
            
 
          
          if (jQuery(this).val()) {
               jQuery('.statetext option').css("color", "#919ca1");
               jQuery('.statetext').find("option:selected").css("color", "#44484c");
               jQuery('.statetext').css("color", "#44484c")
          } else {
                jQuery('.statetext').css("color", "#919ca1");
                jQuery('.statetext option').css("color", "#919ca1");
          }
                  
             getAreas(cityId,1);
     });  
           
     jQuery("#state-list2").on("change", function(ev) {  
      jQuery('#area-list2').children('option:not(:first)').remove();
      var cityId2 = jQuery("option:selected", this).val();
          
         if (jQuery(this).val()) {
               jQuery('.statetext2 option').css("color", "#919ca1");
               jQuery('.statetext2').find("option:selected").css("color", "#44484c");
               jQuery('.statetext2').css("color", "#44484c")
          } else {
                jQuery('.statetext2').css("color", "#919ca1");
                jQuery('.statetext2 option').css("color", "#919ca1");
          }
                
      getAreas(cityId2,2);
     });
     
     
     
      jQuery("#area-list").on("change", function(ev) {        
         if (jQuery(this).val()) {
               jQuery('.areatext option').css("color", "#919ca1");
               jQuery('.areatext').find("option:selected").css("color", "#44484c");
               jQuery('.areatext').css("color", "#44484c")
          } else {
                jQuery('.areatext').css("color", "#919ca1");
                jQuery('.areatext option').css("color", "#919ca1");
          }
     });
     
     jQuery("#area-list2").on("change", function(ev) {        
         if (jQuery(this).val()) {
               jQuery('.areatext2 option').css("color", "#919ca1");
               jQuery('.areatext2').find("option:selected").css("color", "#44484c");
               jQuery('.areatext2').css("color", "#44484c")
          } else {
                jQuery('.areatext2').css("color", "#919ca1");
                jQuery('.areatext2 option').css("color", "#919ca1");
          }
     });
     
     
     
     
})();
</script>

<script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/jquery.validate.min.js"></script>
<script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/additional-methods.min.js"></script>
<script>
  jQuery( document ).ready(function() {
 
   $('#signup-first input[type="text"]').tooltipster({
        trigger: 'custom',
        onlyOne: false,
        position: 'bottom-left'
    });
      $('#signup-first input[type="email"]').tooltipster({
        trigger: 'custom',
        onlyOne: false,
        position: 'bottom-left'
    });
     $('#signup-first input[type="tel"]').tooltipster({
        trigger: 'custom',
        onlyOne: false,
        position: 'bottom-left'
    });
       $('#signup-first  select').tooltipster({
        trigger: 'custom',
        onlyOne: false,
        position: 'bottom-left'
    });
    
    
    $('#signup-second input[type="text"]').tooltipster({
        trigger: 'custom',
        onlyOne: false,
        position: 'bottom-left'
    });
      $('#signup-second input[type="email"]').tooltipster({
        trigger: 'custom',
        onlyOne: false,
        position: 'bottom-left'
    });
     $('#signup-second input[type="tel"]').tooltipster({
        trigger: 'custom',
        onlyOne: false,
        position: 'bottom-left'
    });
       $('#signup-second  select').tooltipster({
        trigger: 'custom',
        onlyOne: false,
        position: 'bottom-left'
    });
    
    
    
    jQuery.validator.addMethod("lettersonly", function(value, element) 
    {
    return this.optional(element) || /^[a-z]+$/i.test(value);
    }, "Letters only please");

    jQuery.validator.addMethod(
                "tendigits",
                function (value, element) {
                    if (value == "")
                        return false;
                    return value.match(/^\d{10}$/);
                },
                "Please enter 10 digits");

   jQuery("#signup-first").validate({
   
       onfocusout: function (element) {
                $(element).valid();
            },
      errorPlacement: function (error, element) {
                        
            var lastError = $(element).data('lastError'),
                newError = $(error).text();
            
            $(element).data('lastError', newError);
                            
            if(newError !== '' && newError !== lastError){
                $(element).tooltipster('content', newError);
                $(element).tooltipster('show');
            }
        },
        success: function (label, element) {
            $(element).tooltipster('hide');
        },
   errorClass: "error-field",
   validClass:"valid_class",
        rules: {
            "first-name": {
                required: true,
                lettersonly: true
            },
            "last-name": {
                required: true,
                lettersonly: true
            },
            "email-address": {
                required: true,
                email: true
            },
            "phone-number": {
                required: true,
                number: true,
                tendigits: true
              }
        },
        
      messages: {
      firstname: {
      required: "Please enter first name",
     },      
     lastname: {
      required: "Please enter last name",
     },     
     "phone-number": {
      required: "Please enter phone number",
      digits: "Please enter valid phone number",
      minlength: "Phone number field accept only 10 digits",
      maxlength: "Phone number field accept only 10 digits",
     },     
     email: {
      required: "Please enter email address",
      email: "Please enter a valid email address.",
     },
    }
 });    
 
jQuery("#signup-second").validate({
    onfocusout: function (element) {
                $(element).valid();
            },
   errorPlacement: function (error, element) {
                        
            var lastError = $(element).data('lastError'),
                newError = $(error).text();
            
            $(element).data('lastError', newError);
                            
            if(newError !== '' && newError !== lastError){
                $(element).tooltipster('content', newError);
                $(element).tooltipster('show');
            }
        },
        success: function (label, element) {
            $(element).tooltipster('hide');
        },
   errorClass: "error-field",
   validClass:"valid-field",
   rules: {
            "first-name-2": {
                required: true,
                lettersonly: true
            },
            "last-name-2": {
                required: true,
                lettersonly: true
            },
            "email-address-2": {
                required: true,
                email: true
            },
            "phone-number-2": {
                required: true,
                number: true,
                tendigits: true
              }
        }
     
  }); 
  
});
</script>

<style>
/*tooltip */
/* This is the default Tooltipster theme (feel free to modify or duplicate and create multiple themes!): */
.tooltipster-default {
	border-radius: 5px; 
	border: none;
	background: #FF3939;
	color: #fff;
}

/* Use this next selector to style things like font-size and line-height: */
.tooltipster-default .tooltipster-content {
	font-family: Arial, sans-serif;
	font-size: 14px;
	line-height: 16px;
	padding: 8px 10px;
	overflow: hidden;
}

/* This next selector defines the color of the border on the outside of the arrow. This will automatically match the color and size of the border set on the main tooltip styles. Set display: none; if you would like a border around the tooltip but no border around the arrow */
.tooltipster-default .tooltipster-arrow .tooltipster-arrow-border {
	/* border-color: ... !important; */
}


/* If you're using the icon option, use this next selector to style them */
.tooltipster-icon {
	cursor: help;
	margin-left: 4px;
}


/* This is the base styling required to make all Tooltipsters work */
.tooltipster-base {
	padding: 0;
	font-size: 0;
	line-height: 0;
	position: absolute;
	z-index: 9999999;
	pointer-events: none;
	width: auto;
	overflow: visible;
}
.tooltipster-base .tooltipster-content {
	overflow: hidden;
}


/* These next classes handle the styles for the little arrow attached to the tooltip. By default, the arrow will inherit the same colors and border as what is set on the main tooltip itself. */
.tooltipster-arrow {
	display: block;
	text-align: center;
	width: 100%;
	height: 100%;
	position: absolute;
	top: 0;
	left: 0;
	z-index: -1;
}
.tooltipster-arrow span, .tooltipster-arrow-border {
	display: block;
	width: 0; 
	height: 0;
	position: absolute;
}
.tooltipster-arrow-top span, .tooltipster-arrow-top-right span, .tooltipster-arrow-top-left span {
	border-left: 8px solid transparent !important;
	border-right: 8px solid transparent !important;
	border-top: 8px solid;
	bottom: -7px;
}
.tooltipster-arrow-top .tooltipster-arrow-border, .tooltipster-arrow-top-right .tooltipster-arrow-border, .tooltipster-arrow-top-left .tooltipster-arrow-border {
	border-left: 9px solid transparent !important;
	border-right: 9px solid transparent !important;
	border-top: 9px solid;
	bottom: -7px;
}

.tooltipster-arrow-bottom span, .tooltipster-arrow-bottom-right span, .tooltipster-arrow-bottom-left span {
	border-left: 8px solid transparent !important;
	border-right: 8px solid transparent !important;
	border-bottom: 8px solid;
	top: -7px;
}
.tooltipster-arrow-bottom .tooltipster-arrow-border, .tooltipster-arrow-bottom-right .tooltipster-arrow-border, .tooltipster-arrow-bottom-left .tooltipster-arrow-border {
	border-left: 9px solid transparent !important;
	border-right: 9px solid transparent !important;
	border-bottom: 9px solid;
	top: -7px;
}
.tooltipster-arrow-top span, .tooltipster-arrow-top .tooltipster-arrow-border, .tooltipster-arrow-bottom span, .tooltipster-arrow-bottom .tooltipster-arrow-border {
	left: 0;
	right: 0;
	margin: 0 auto;
}
.tooltipster-arrow-top-left span, .tooltipster-arrow-bottom-left span {
	left: 6px;
}
.tooltipster-arrow-top-left .tooltipster-arrow-border, .tooltipster-arrow-bottom-left .tooltipster-arrow-border {
	left: 5px;
}
.tooltipster-arrow-top-right span,  .tooltipster-arrow-bottom-right span {
	right: 6px;
}
.tooltipster-arrow-top-right .tooltipster-arrow-border, .tooltipster-arrow-bottom-right .tooltipster-arrow-border {
	right: 5px;
}
.tooltipster-arrow-left span, .tooltipster-arrow-left .tooltipster-arrow-border {
	border-top: 8px solid transparent !important;
	border-bottom: 8px solid transparent !important; 
	border-left: 8px solid;
	top: 50%;
	margin-top: -7px;
	right: -7px;
}
.tooltipster-arrow-left .tooltipster-arrow-border {
	border-top: 9px solid transparent !important;
	border-bottom: 9px solid transparent !important; 
	border-left: 9px solid;
	margin-top: -8px;
}
.tooltipster-arrow-right span, .tooltipster-arrow-right .tooltipster-arrow-border {
	border-top: 8px solid transparent !important;
	border-bottom: 8px solid transparent !important; 
	border-right: 8px solid;
	top: 50%;
	margin-top: -7px;
	left: -7px;
}
.tooltipster-arrow-right .tooltipster-arrow-border {
	border-top: 9px solid transparent !important;
	border-bottom: 9px solid transparent !important; 
	border-right: 9px solid;
	margin-top: -8px;
}


/* Some CSS magic for the awesome animations - feel free to make your own custom animations and reference it in your Tooltipster settings! */

.tooltipster-fade {
	opacity: 0;
	-webkit-transition-property: opacity;
	-moz-transition-property: opacity;
	-o-transition-property: opacity;
	-ms-transition-property: opacity;
	transition-property: opacity;
}
.tooltipster-fade-show {
	opacity: 1;
}

.tooltipster-grow {
	-webkit-transform: scale(0,0);
	-moz-transform: scale(0,0);
	-o-transform: scale(0,0);
	-ms-transform: scale(0,0);
	transform: scale(0,0);
	-webkit-transition-property: -webkit-transform;
	-moz-transition-property: -moz-transform;
	-o-transition-property: -o-transform;
	-ms-transition-property: -ms-transform;
	transition-property: transform;
	-webkit-backface-visibility: hidden;
}
.tooltipster-grow-show {
	-webkit-transform: scale(1,1);
	-moz-transform: scale(1,1);
	-o-transform: scale(1,1);
	-ms-transform: scale(1,1);
	transform: scale(1,1);
	-webkit-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
	-webkit-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15); 
	-moz-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15); 
	-ms-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15); 
	-o-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15); 
	transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15);
}

.tooltipster-swing {
	opacity: 0;
	-webkit-transform: rotateZ(4deg);
	-moz-transform: rotateZ(4deg);
	-o-transform: rotateZ(4deg);
	-ms-transform: rotateZ(4deg);
	transform: rotateZ(4deg);
	-webkit-transition-property: -webkit-transform, opacity;
	-moz-transition-property: -moz-transform;
	-o-transition-property: -o-transform;
	-ms-transition-property: -ms-transform;
	transition-property: transform;
}
.tooltipster-swing-show {
	opacity: 1;
	-webkit-transform: rotateZ(0deg);
	-moz-transform: rotateZ(0deg);
	-o-transform: rotateZ(0deg);
	-ms-transform: rotateZ(0deg);
	transform: rotateZ(0deg);
	-webkit-transition-timing-function: cubic-bezier(0.230, 0.635, 0.495, 1);
	-webkit-transition-timing-function: cubic-bezier(0.230, 0.635, 0.495, 2.4); 
	-moz-transition-timing-function: cubic-bezier(0.230, 0.635, 0.495, 2.4); 
	-ms-transition-timing-function: cubic-bezier(0.230, 0.635, 0.495, 2.4); 
	-o-transition-timing-function: cubic-bezier(0.230, 0.635, 0.495, 2.4); 
	transition-timing-function: cubic-bezier(0.230, 0.635, 0.495, 2.4);
}

.tooltipster-fall {
	top: 0;
	-webkit-transition-property: top;
	-moz-transition-property: top;
	-o-transition-property: top;
	-ms-transition-property: top;
	transition-property: top;
	-webkit-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
	-webkit-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15); 
	-moz-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15); 
	-ms-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15); 
	-o-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15); 
	transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15); 
}
.tooltipster-fall-show {
}
.tooltipster-fall.tooltipster-dying {
	-webkit-transition-property: all;
	-moz-transition-property: all;
	-o-transition-property: all;
	-ms-transition-property: all;
	transition-property: all;
	top: 0px !important;
	opacity: 0;
}

.tooltipster-slide {
	left: -40px;
	-webkit-transition-property: left;
	-moz-transition-property: left;
	-o-transition-property: left;
	-ms-transition-property: left;
	transition-property: left;
	-webkit-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
	-webkit-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15); 
	-moz-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15); 
	-ms-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15); 
	-o-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15); 
	transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15);
}
.tooltipster-slide.tooltipster-slide-show {
}
.tooltipster-slide.tooltipster-dying {
	-webkit-transition-property: all;
	-moz-transition-property: all;
	-o-transition-property: all;
	-ms-transition-property: all;
	transition-property: all;
	left: 0px !important;
	opacity: 0;
}


/* CSS transition for when contenting is changing in a tooltip that is still open. The only properties that will NOT transition are: width, height, top, and left */
.tooltipster-content-changing {
	opacity: 0.5;
	-webkit-transform: scale(1.1, 1.1);
	-moz-transform: scale(1.1, 1.1);
	-o-transform: scale(1.1, 1.1);
	-ms-transform: scale(1.1, 1.1);
	transform: scale(1.1, 1.1);
}

/*.scolor{
color:#44484c!important;
}
.scolor option:selected {
   color: #44484c;
}
.scolor option:not(:selected) {
   color: #919CA1;
}*/
/*.signupfieldselect.selectfield option{
color:#919CA1;
}
.signupfieldselect.selectfield option:hover,
.signupfieldselect.selectfield option:focus,
.signupfieldselect.selectfield option:active,
.signupfieldselect.selectfield option:checked

{
color:#000!important;
}*/


</style>
Category: jQuery, Webflow
Balbir KaurPHP and WordPress