Hi,

I'm trying to set the value of an input using the DOM elements but Id I use is never correct.

This is my input:

I've tried with:

SyntaxEditor Code Snippet

document.getElementById(LatAux.Id).value = Lat;

SyntaxEditor Code Snippet

document.getElementById("'"+LatAux.Id+ "'").value = Lat;

SyntaxEditor Code Snippet

document.getElementById("'"+EncodeJavaScript(LatAux.Id) + "'").value = Lat;

and I always get the error:

I'm sure I'm not getting the id in the right way. Any tip? 


Thanks!

Hi,

Where are you putting this JavaScript?

If you put the second format it in an expression XY with escape content set to NO, it should work.

If you put it in an external file, the ID will not be parsed, so you will get this error.

Cheers

P.S. The JavaScript must be load AFTER the element in DOM is built by the browser, or the JavaScript will fail because the element does not exist at the time the JavaScript is executed.

Hi Amelia,

You can try below code.

"document.getElementById('"+LatAux.Id+"').value = "+Lat+";"

What are you actually trying to achieve?

Because like Eduardo said, at first there is no need to use javascript for it.

(There are rare cases to use javascript, but mostly after the intial rendering has been done and the user does something on the client)

Hi Amelia Salgado,

As per my understanding you are trying to update the text box value after page load, if that is the case then in OutSystems the Id value is dynamic as you can see below screen shot.

The best to update the value using class name,follow below steps.

1. Update class name for input.

2. Update java script for that particular web screen

Note : I have included set Timeout function here because java script will load first and then html loads that is the reason I have included set Timeout so that it will wait for html to load and then updates the value.


Hope this helps..


Sravan

J. wrote:

What are you actually trying to achieve?

Because like Eduardo said, at first there is no need to use javascript for it.

(There are rare cases to use javascript, but mostly after the intial rendering has been done and the user does something on the client)

Hi, I'm trying to get the location and save latitude and longitude in two variables.


Thanks


Hi Amelia Salgado,

You can follow above steps mentioned I'm sure you will be able to update the values, let me know if you are facing issue.


Sravan

So, if you need to pass something from JavaScript to OutSystems, throughban Input Widget, best option, I think, is like I explained.

Put your JavaScript in an expression XY at the end of the page.

Cheers.

hope this will help you.

Still,

I am wondering if there's an easier way to solve your problem.

Can you share your oml what you actually want to achieve?