SOLVED: Help, prevent form to reload page

Hello,
I have a form with a text field converted to a button that calls a javascript function that returns the gps coordinates.
Everything works fine, but the problem is that the form is reloaded and the field value is lost.

Is there a way to prevent the form from reloading after executing the javascript function?

Not sure. Is it an option to use a global var to save the value into?

Thanks Aducom,
But the form has many fields and when reloading the value of all of them is lost.

Are you choosing to make the form reload when a user changes a SELECT field? This can often be avoided by using ajax processing - either directly within the field settings or via the
onChange function.

If I create a button with javascript code it works correctly but the button remains in the header.

But if I use a text field like this:

<button onclick="geo()" >Obtain coords</button>

it works but reloads the entire form.

You can try:

<button onclick="geo();return;" >Obtain coords</button>

or

Use the working JavaScript Button by

  • right click > anaylse
  • copy all inside the <a> </a> tag
  • and insert this into your text/label field

Best

Gunter Eibl

HI GunterEibl,

Finally it wor’s with this code:

<button onclick="geo();return false;" >Obtain coords</button>

Thanks