Using Variables in WhatsApp Message Text
-
Hello!
I am using the Calculated Fields Form plugin to create a form on WordPress. I want a button to open a new window with WhatsApp Web and populate the form field values in the message. I have written the following code in the OnClick event for the button:(function() {
// Get field values
const name = fieldname1; // Name
const phone = fieldname2; // Phone
const area = fieldname7; // Area
// Create the message text (text for example)
const message = encodeURIComponent(
Hello, I am contacting you through your website. My name is ${name}, my phone number is ${phone}. I want to order project, area is ${area} m2.
);
// Create the WhatsApp Web link
const whatsappUrl =https://web.whatsapp.com/send?phone=18002428478&text=${message};
// Open WhatsApp Web in a new window
window.open(whatsappUrl, '_blank');
})();However, when I click the button, nothing happens. Could you please tell me what is wrong with this code? Why isn’t it working? Am I accessing the form fields incorrectly, or am I missing something? Thank you in advance for your help!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Using Variables in WhatsApp Message Text’ is closed to new replies.