429
Views
11
Comments
Solved
Change input value by javascript
Question

I am trying to change an input value inside a  screen by javascript in a webblock inside, in the webblock I have something like 'getElementById({id of the input }.value='something'; .

The value of the input changes but what is not changing is the local variable in the screen binded to it.

what is the best practice to achieve this?

2025-08-07 06-30-56
Amit J
Champion
Solution

you can not change the local variables by javascript while on-screen elements(HTML tag like input) we can change the value via javascript. To change the value in the local variable you have to assign value anyhow on the screen action.

2022-01-13 08-29-52
Saravanan Santhanam

Hi Filipe,

If you assign a value on basis of Js, there are two approaches you can follow 

i) If your using the script in any client action just set one Output parameter for the script with the respective value assigned, and assign that Output parameter to the local variable on the next step.

ii) If you're passing the value from web block using trigger event, In the event handler of the screen assign the local variable with the value.

Hope it helps!

Regards,

Saravanan Santhanam.

2024-01-05 16-00-17
Filipe Lourenço

" If your using the script in any client action just set one Output parameter for the script with the respective value assigned, and assign that Output parameter to the local variable on the next step. "

The local variable and the input is in the screen, not in the webblock, in the webblock I have placeholders

2022-01-13 08-29-52
Saravanan Santhanam

Can you pls share any screenshot or sample oml to understand, how you set the value for the input widget?

2024-01-05 16-00-17
Filipe Lourenço
2022-01-13 08-29-52
Saravanan Santhanam


As per the screenshot, I can understand your assigning value to the input in the Web block level. Since you don't have access to the screen's local variable, you need to trigger an event with an Input parameter and pass the value to the triggered event, In the handler client action of the screen just assign the value to the local variable.

2020-09-01 10-42-42
Stefano Valente

Are you trying to do this for educational purposes ?

Because i am very curious as to why you want to resort to javascript for something OS offers you in client actions (which is better maintainable than JS).


2024-01-05 16-00-17
Filipe Lourenço

No. I am trying to create a widget with the possibility of the input and textarea in the calling side. If you know how to do it with Outsystems client actions , please go forward, how to set inside the webblock something that is outside?

2020-09-01 10-42-42
Stefano Valente

I am not sure what you mean by this. 

You can now access the value through the local variable, but this does not work for you?


I did create a formatmask for inputwidgets once. For his you need javascript, but even then i try to only use js to create events. And the logic i still put inside client actions and call them from js.

Are you trying something similar?

2024-01-05 16-00-17
Filipe Lourenço

I think you didn't understand , the input is in a screen and the widget is a webblock (where I am trying to set the value of the input) , how do you access the local variable that is in the screen inside the webblock?

2020-09-01 10-42-42
Stefano Valente

To have the input in your screen changed when something in your webblock changes, you can create an event and trigger it. then handle that event in your screen.

Example:

1: the input on the screen

2: the webblock.



and the raiseeventclick action in the webblock:


2025-08-07 06-30-56
Amit J
Champion
Solution

you can not change the local variables by javascript while on-screen elements(HTML tag like input) we can change the value via javascript. To change the value in the local variable you have to assign value anyhow on the screen action.

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