1590
Views
10
Comments
DOM elements by Id
Question

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!

2026-06-05 12-38-17
Eduardo Jauch

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

2026-06-05 12-38-17
Eduardo Jauch

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.

UserImage.jpg
Pratham. Polekar

Hi Amelia,

You can try below code.

"document.getElementById('"+LatAux.Id+"').value = "+Lat+";"
2016-04-21 20-09-55
J.
 
MVP

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)

UserImage.jpg
Amelia Salgado

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


2019-01-04 10-45-45
Sravan Vanteru

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

2019-01-04 10-45-45
Sravan Vanteru

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

2026-06-05 12-38-17
Eduardo Jauch

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.

UserImage.jpg
Pratham. Polekar

hope this will help you.

JavaScriptVal.oml
2016-04-21 20-09-55
J.
 
MVP

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?


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.