Hello,
I have an embeded HTML form on one page.
In this form, I would like to check if the number is not less that 100.
In HTML code I put following script
<script type="text/javascript">
// When the message is coming after check
window.onmessage = (event) => {
if (event.data) {
document.getElementById("alert").innerHTML = event.data;
}
}
// I get the value from input with ID "somme"
var sumToCheck = document.getElementById("somme").value;
// If changed, the message should be send to WIX part
sumToCheck.addEventListener('change', function(){
window.parent.postMessage(sumToCheck, "https://www.mysite.me");
});
In page code I put following script
$w.onReady(function () {
// when a message is received from the HTML element
$w("#htmlForm").onMessage( (event) => {
console.log("Message from HTML = " + event.data);
var sumToCheck = event.data;
const minSum = 990;
if (sumToCheck < minSum || typeof sumToCheck != "number" || isNaN(sumToCheck)) {
var alertMsg = `The sum can't be less 100`;
console.log('not good');
// send message to the HTML element
htmlForm_message(event);
} else {
console.log('it'OK');
}
});
});
export function htmlForm_message(event) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
$w("#htmlForm").postMessage(`The sum can't be less 100`);
}
When I test, nothing happen… It seams that the message not arrives from HTML form… Why? I don’t understand… I do according to documentation… But… it doesn’t work
Where is the problem?
Could somebody help me?
Thanks in advance