I am new to jquery and I'm trying to get the values from the SelectedCountryData
object in intl-tel-input
after form submission.
From the documentation getSelectedCountryData
returns something like below and I want to get the value "93" from it:
{
name: "Afghanistan (افغانستان)",
iso2: "af",
dialCode: "93"
}
I can successfully return the phone number but [calling_code] => [object Object]
is returned for the calling code when I use the following:
$("form").submit(function() {
$("#phone-full").val($("#phone").intlTelInput("getNumber")); //this works
$("#calling_code").val($("#phone").intlTelInput("getSelectedCountryData")); //this doesn't
});
Here are the form input fields:
<input type="tel" id="phone" value="<?php echo $phone_number ?>">
<input id="phone-full" type="hidden" name="phone_number">
<input id="calling_code" type="hidden" name="calling_code">