Return javascript variable back to Form

Thank you for your quick reply.

From your answer, it sounds like using a simple “return” from the javascript code doesn’t work.

I had already read through the documentation you cited and tried the anvil.call() but without success.I think my fundamental problem is that I don’t understand the bridge between the python and the custom javascript sections. And having almost no jquery experience, I’m probably further behind than the average Anvil user.

I was able to find a thread that I’m pretty sure points to my issue:

In it meredydd describes how the anvil.call() needs to know which form element the method is attached to, thus the use of anvil.call(this, 'submit_clicked', formData); doesn’t work unless the “this” is associated with a DOM element. And that’s the rub. Unlike the example where they are discussing a clickable link providing that DOM reference, I’m just trying to get my javascript function to run and return the ip address without any particular link or button being fired by the user. I was hoping meredydd in his explanation would describe some kind of simple assignment of “this” just to the page load.

david.wylie describes a work-around using divs to provide a connection to the DOM, and I was able to get that method to work. But it seems strange to me to have to create invisible div elements in my Custom HTML section in order to trick my javascript function to communicate back with the python code. I’d much rather have my javascript write information directly into hidden Label or Textbox Components created/managed by the python code, but I couldn’t figure out how the javascript could get access to them. Especially since it doesn’t seem that the Components support the “id” tag in order to reference them. Like I mentioned earlier, my lack of jquery/DOM manipulation is probably my impediment in this area.

Thanks again for your timely response.

Cheers,

Doug