Return javascript variable back to Form

here is a simple app that returns a value from a javascript function with no problems

https://anvil.works/build#clone:ZCC3CMWDKWOLUHJX=BK7VOUJUN6GYPAV5BJ56JPAR

def form_show(self, **event_args):
  foo = self.call_js('checkJsReturns')
  print(foo) # bar
<script>
function checkJsReturns() {
  return 'bar'
}
</script>

Alternative approaches here:
You can get the ip address from the server

#client
anvil.server.call('get_ip')
#serverside
@anvil.server.callable
def get_ip():
    print(anvil.server.context.ip)

https://anvil.works/docs/server/call-context

4 Likes