Good day to all, faced with such a problem, there is one input field input id = "siF3" and I give a list select id = "country" in the list of several countries when choosing a country, the tax code number should be set but the code does not work alert will work mask no.

PS The jquery 3.1.1 library is connected and the js mask is also

here is the code

$("#country").on("change", function() { alert(this.value); if ($("#country").val() == "oe") { $("#siF3").mask("ATU-99999999"); } else if (($("#country").val() == "de")) { $("#siF3").mask("DE-99999999"); } }); 
 <script src="http://www.smartled-schweiz.ch/js/jquery-3.1.1.min.js" type="text/javascript"></script> <script src="http://www.smartled-schweiz.ch/js/jquery.maskedinput.min.js" type="text/javascript"></script> <select id="country" class="strani"> <option id="land1" value="oe">Österreich</option> <option id="land2" value="de">Deutschland</option> <option id="land3" value="belgien">Belgien</option> <option value="bulgarien">Bulgarien</option> <option value="danemark">Dänemark</option> <option value="estland">Estland</option> <option value="finnland">Finnland</option> <option value="frankreich">Frankreich</option> <option value="griechenland">Griechenland</option> <option value="irland">Irland</option> <option value="italien">Italien</option> <option value="kroatien">Kroatien</option> <option value="lettland">Lettland</option> <option value="litauen">Litauen</option> <option value="luxemburg">Luxemburg</option> <option value="malta">Malta</option> <option value="niederlande">Niederlande</option> <option value="polen">Polen</option> <option value="portugal">Portugal</option> <option value="Rumanien">Rumänien</option> <option value="schweden">Schweden</option> <option value="slowakei">Slowakei</option> <option value="spanien">Spanien</option> <option value="tschechische">Tschechische Republik</option> <option value="ungarn">Ungarn</option> <option value="vereinigtes">Vereinigtes Königreich</option> <option value="zypern">Zypern</option> </select> <div> <input id="siF3" name="UID" size="20" style="width:100%;" value="" maxlength="30" type="text"> </div> 

  • one
    "The jquery 3.1.1 library is connected and the js is also mapped" - well, insert them into your code, connect both fragments into one and add input - Igor
  • Already done, but the result of the zero alert works, but the mask does not and slightly changed the code, but there’s no use. $ ("# country option: selected"). val () == "oe") - Narek Nik Hovsepyan
  • one
    paste them into your code in question - Igor
  • maybe I look stupid but everything is set on the page. = ( - Narek Nik Hovsepyan
  • Attach the necessary files to the snippet so that you can try to reproduce your problem right here. - br3t

1 answer 1

In fact, the mask is used, simply because input without focus, the mask is not visible. If you need to see it, you must forcibly add focus to the input:

  $("#country").on("change", function() { alert(this.value); if ($("#country").val() == "oe") { $("#siF3").mask("ATU-99999999").focus(); } else if (($("#country").val() == "de")) { $("#siF3").mask("DE-99999999").focus(); } }); 
  • Everything works here, but the mask does not work on the site, okay, I will decide the question thanks to everyone ... - Narek Nik Hovsepyan