function myFunction2() {
    var id = document.getElementById("staffid").value;
    var tel_no = "6" + document.getElementById("tel_no").value;
    var link = 'https://wa.me/' + tel_no + '?text=http://survey.pharmaniaga.com/REGISTER/index.php?id=' + id;
    var data = '<a href="https://wa.me/' + tel_no + '?text=http://survey.pharmaniaga.com/REGISTER/index.php?id=' + id + '" title="Share on whatsapp">WhatsApp</a>';



    // Set the QR code data to the hidden input field
    document.getElementById("qrCodeData").value = link;

    // Send an AJAX request to store the data
    saveQRCodeData(link);

    // Update the UI to show the WhatsApp link
    document.getElementById("demo").innerHTML = data;

    if (data != "") {
        var url = "https://api.qrserver.com/v1/create-qr-code/?size=1000x1000&data=" + link;
        document.getElementsByClassName("qr-code")[0].style.backgroundImage = "url(" + url + ")";
        document.getElementsByClassName("qr-code")[0].style.backgroundSize = "100% 100%";
        document.getElementsByClassName("qr-code")[0].innerHTML = "";
        document.getElementsByClassName("qr-code")[0].style.border = "0";
    } else {
        return false;
    }
}

function saveQRCodeData(data) {
    // Send an AJAX POST request to save the data to the server
    var xhr = new XMLHttpRequest();
    xhr.open("POST", "/save-qr-code-data", true);
    xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
    xhr.send(JSON.stringify({ qrCodeData: data }));

    // Handle the response from the server if needed
    xhr.onreadystatechange = function () {
        if (xhr.readyState === XMLHttpRequest.DONE) {
            if (xhr.status === 200) {
                console.log("Data saved successfully.");
            } else {
                console.error("Error saving data.");
            }
        }
    };
}
