How to get values from html iFrame?

So I have an html element iFrame and I can send html code in it that runs perfectly with .postmessage; however I have been unable to work out how to get the html inside the element to send data out of the element.

I know that I have to use postmessage() again however I cannot get it to work on the click of a button. I have used the examples in the Corvid Reference section and can return automatic statements but I want different values to be returned by different buttons.

I thought this would work:

var x = document.createElement("Value2);
<button type=“button” onclick=“sendReturnMessage(“Value 1”);”>Button 1
Button 2

But it does not. Is there any way that it can be done?

Try something like:

<!DOCTYPE html>
<html>
<body>
<button id="button1" onclick="postMsg('value1')">button1</button>
<button id="button2" onclick="postMsg('value2')">button2</button>
<script>
function postMsg(msg) {
   window.parent.postMessage(msg, "*");
}
</script>
</body>
</html>

Thank you that does work, however I need it to also work with variable outputs and also with code that is entered from the page. Is that possible?

it is possible.
See https://www.wix.com/corvid/reference/$w.HtmlComponent.html#postMessage

I already went though all of that and could not work out how to get it to work. I sent the code in and it would not return any values back.

Post your code.

Never mind I got it to work, thank you for your help.