I have a simple contact form on my website which is created using online builder (so I can't change the html code and add id't to elements). Here is the example of my form:
https://jsfiddle.net/kerm131/w6oa7uhe/30/
$("[data-type='phone'] .input .form-control").intlTelInput({
allowDropdown: true,
autoPlaceholder: "aggressive",
initialCountry: "auto",
geoIpLookup: function(success, failure) {
$.get("https://ipinfo.io", function() {}, "jsonp").always(function(resp) {
var countryCode = (resp && resp.country) ? resp.country : "";
success(countryCode);
});
},
});
let country = document.querySelector('selected-flag[title]');
$("[data-type='hidden'] .input .form-control").val($(country));
.field {
padding: 10px 0;
}
.form-control {
padding: 10px;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/14.0.6/css/intlTelInput.css">
<div class="fields">
<div class="field" data-type="name" style="width: 247px;">
<div class="input"><input class="form-control text" type="text" data-placeholder="true" value="Wie sollen wir Sie ansprechen?" style="border-radius: 15px;"></div>
</div>
<div class="field" data-type="phone" style="width: 247px;">
<div class="input"><input class="form-control text" type="text" data-placeholder="true" style="border-radius: 15px;"></div>
</div>
<div class="field" data-type="email" style="width: 247px;">
<div class="input"><input class="form-control text" type="text" data-placeholder="true" value="E-Mail Adresse *" style="border-radius: 15px;"></div>
</div>
<div class="field" data-type="hidden" style="width: 247px;">
<div class="input"><input class="form-control" type="text" style="border-radius: 15px;" value="hidden content"></div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/14.0.6/js/intlTelInput-jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/14.0.6/js/utils.js"></script>
There is int-tel-input jQuery plugin in the field for telephone number that sets country dial code using user ip. I want duplicate this information to the hiddden field. Or to be more exact, take data from attribute "title" of element with class .selected-flag and fill in this information "hidden" field.
Unfortunately, I have very poor skills in JS and jQuery, so I can't figure out how to make it works. You can see my attempts in the JS code field.
Please, give me a hint or solution to solve my problem.