I need to read the value of a Javascript variable (JS2GO
) in my Go code (v.Hostname
). I do not know how to do it.
I have read a bit about syscall/js
but I could not find anything.
It is the Javascript code:
$(document).on("keypress", "input", function(e){
if(e.which == 13){
var JS2GO = $(this).val();
}
});
And here is the form I have in my .gohtml
file.
<form method="POST">
<input id="myInput" type="text" name="host">
<input type="submit" style="position: absolute; left: -9999px; width: 1px; height: 1px;" tabindex="-1">
</form>
P.S.
I came up with this solution because I can't click on "submit" button (it is hidden), then it doesn't send the results to my Go code. It means that I cannot read the value of input
by this code: v.Host = r.FormValue("host")
. Please let me know if my approach is not optimal.