I am modifying a code that sends sales tickets by WhatsApp. In theory, a modal window opens and the phone number is entered when clicking on send, this should send the whatsapp message to the entered number, but I cannot collect the information from the modal to put it in a variable
<div class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1"
aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="staticBackdropLabel">Título del modal</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="box-body">
<!-- ENTRADA PARA NUMERO -->
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-cash-register"></i></span>
<input type="text" class="form-control input-lg" name="telefono" id="telefono" placeholder="NUMERO TELEFONICO" required>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cerrar</button>
<button type="button" class="btn btn-primary" onclick="enviarMensaje()" >ENVIAR</button>
</div>
</div>
</div>
</div>
<script type="text/javascript" language="javascript">
function enviarMensaje() {
var tel= document.getElementById("telefono").value;
var url = "https://api.whatsapp.com/send?phone=52$(tel)";
window.open(url);
}
</script>
Create your url like this
You are trying to use template strings , but the syntax is with braces {} and not with parentheses () and also the string must be enclosed in right or back quotes.
Alternatively you can also do it in a more traditional way
i solved it this way thanks for your input