I use a field for obtaining phone numbers, now I added a field to show the country codes through intl-tel-input through code mentioned below. However, when I attempt to submit the form, the code is not attached, and only the numbers are sent. I'm not versed with JS syntax, however understood it enough through YouTube videos to have it functional. It is using the backend of Google forms (not the best way but serves the purpose). How can I add the country code along with the WhatsApp number (#whatsappno
) in the code. I believe the change needed would be around var field3 = $("#whatsappno").val();
to replace #whatsappno
(example: country code: +1, number: 9998886664 —> +19998886664) through the form when I receive it.
Edit to avoid duplication: I am also unsure which variables have I to use to concatenate.
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.8/css/intlTelInput.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.8/js/intlTelInput.min.js"></script>
<form>
<div>
<p class="required-form">*</p>
<fieldset>
<input type="tel" name="blah" id="whatsappno" placeholder="Whatsapp number" required/>
</fieldset>
</div>
<div>
<fieldset>
<button type="submit" id="contact">Submit Application</button>
</fieldset>
</div>
</form>
<script>
const phoneInputField = document.querySelector("#whatsappno");
const phoneInput = window.intlTelInput(phoneInputField, {
utilsScript: "https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.8/js/utils.js",
});
function postToGoogle() {
var field3 = $("#whatsappno").val();
$.ajax({
url: "https://docs.google.com/forms/d/e/…….?”,
data: {“val.123456789”: field3 },
type: "POST",
dataType: "xml",
success: function (d) {
},
error: function (x, y, z) {
$('#success-msg').show();
$('#contact').hide();
}
});
return false;
}
</script>
</html>
const
, and the variable later is defined usingvar field3 = $("#whatsappno").val();
I just want to replace that#whatsappno
with the country code and whatsapp number. (+1 and 9998886664 —> +19998886664 Thing is I don't know what is the first variable, and if it's defined by definition, since whoever made this code, must've naturally thought that it would be combined(my logic) and I've seen examples of that online(to substantiate that). Something about the constphoneInput
made me feel it's combined.