2

Writing Golang app using github.com/zserge/lorca package. This binds golang funcs to Javascript. I have HTML with text input and submit button which should pass the text input as an arg into the Javascript binding. It looks as follows:

<input type="text" name="MACADD" style="height:20px; width:210px">
<input type="submit" value="submit" onclick="JSBINDFUNC(MACADD)">

The JSBINDFUNC takes golang type string for input. When I hit submit, it should be passing the text entered for MACADD as an arg into the JSBINDFUNC func.

However, I'm coming back with the err

exception":{"type":"string","value":"json: cannot unmarshal object into Go value of type string"}

Needing this object to become golang string.

More complete snip:

package main

import (
    "fmt"
    "log"
    "net/url"

    "github.com/zserge/lorca"
)

func main() {
    ui, err := lorca.New("data:text/html,"+url.PathEscape(`
        <html>
                <form action="/action_page.php">
                    MAC Address:<br>
                    <input type="text" name="MACADD" style="height:20px; width:210px">
                    <input type="submit" value="Submit" onclick="JSBINDFUNC(MACADD)">
                </form> 
            </body>
        </html>
        `), "", 480, 320)
    if err != nil {
        log.Fatal(err)
    }
    //ui.Bind implemented @ https://github.com/zserge/lorca/blob/master/ui.go#L110
    ui.Bind("JSBINDFUNC", func(MAC string) {
        fmt.Println(MAC)
        return
    })
    defer ui.Close()
    <-ui.Done()
}

4
  • You need to post your go-code snippet. Not being familiar with this pkg, I would suspect one marshals form data into a struct - since forms have many fields - and marshaling into a single string will not work. Commented Mar 27, 2019 at 19:09
  • 1
    @colminator just updated, you should be able to copy/paste, go build and get the exact error. Make sure you've got Chrome installed. Commented Mar 27, 2019 at 19:50
  • 2
    should html be something like MACADD.value ? Commented Mar 27, 2019 at 19:53
  • @atayenel GENIUS. Thank you. Commented Mar 27, 2019 at 20:05

1 Answer 1

3

The issue is with your javascript. Update your onclick attribute like so:

<input type="submit" value="Submit" onclick="JSBINDFUNC(MACADD.value)">
Sign up to request clarification or add additional context in comments.

3 Comments

I just changed JSBINDFUNC(MACADD) to JSBINDFUNC(MACADD.value) per @atayenel. This works.
I justed edited the answer to reflect @atayenel shorter suggestion
I like lorca. I'm glad it was html problem and not a lorca problem :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.