I need to have a function that returns the value of a form to my WASM code when a button is clicked.
I tried
let formText = ''
//import init, {greet} from "./pkg/hello_wasm.js";
Element.prototype.remove = function() {
this.parentElement.removeChild(this);
}
function getFormText(){
formText = document.getElementById('tField').value
}
function readDom(){
document.write('<input type="text" id="tField"><button type="button" id="submit" onClick = "getFormText()">Submit</button>')
while(formText == ''){
}
let bufText = formText
document.getElementById('tField').remove
document.getElementById('submit').remove
formText = ''
return bufText
}
document.write(readDom())
/*init()
.then(() => {
greet("WebAssembly")
});*/
but it just froze my browser.
I looked up “wait for button click” and stuff like that on DuckDuckGo but the results I got didn’t do what I needed.
Putting the document.write in the callback won’t work because the function is meant to be called from WASM/return to WASM I just have the WASM commented out so I don’t have to recompile my code just to test changes to a JS function.