Value Not pass to Local Variable using jquery

Value Not pass to Local Variable using jquery

  

Hello,
In the below picture I write a jquery code and value assigned to output parameter and set this value to message. Here 1st time I get the value but after that I didn't get any value. I don't know what happen with this.

JQuery Code:


$('.handle1').change(function(e){
        $parameters.GetValue = "";
        var Slideval = "";
        Slideval = e.value;
        $parameters.GetValue = Slideval;
        alert($parameters.GetValue);
        $resolve();
});

In alert I get the value every time but I message I didn't get any response. Please help me out from this.

It is for mobile app.

Hi Suhas,

I assume this code lives in a Screen Action? When is this Screen Action called? Did you debug your code?

Hello Kilian,

On parameter Changed action I set this code. I get alert every time when parameters changed but in messaging I didn't get changed value.  

Suhas,

Are you sure you are assigning javascript block's output to your message?

Hello Suraj,

$('.handle1').change(function(e){
        $parameters.GetValue = "";
        var Slideval = "";
        Slideval = e.value;
        $parameters.GetValue = Slideval;
        alert($parameters.GetValue);
        $resolve();
});


$parameters.GetValue this is output parameter.

Hi Suhas,

Some observations about the JavaScript:

1) If you can avoid it, don't use JQuery in mobile. It's pretty bloated and may/will affect performance.

2) Why do you first set $parameters.GetValue to "", then always to another value? The former seems superfluous.

3) Same for Slideval, why not directly assign it to e.value? Or better yet, why not assign e.value directly to $parameters.GetValue?

4) What's the $resolve for?

That said, can you share an eSpace that shows what you're doing, as I'm not sure I understand how you've set up things.

Hello Kilian,

I already Slideval = e.value but it not working so I made a changes.
This is asynchronous that why I use $resolve.
See the attachment.

Solution

Hi Suhas,

I think I know what's going on, but since I'm not a JavaScript wizard, I'm not 100% sure.

What I think happens:

  1. You specify an onclick handler in OutSystems. This is executed.
  2. In the handler of the onclick (handle1OnChange), in the JavaScript you actually set a handler (the JQuery change handler) for the widget, which shows the alert.
  3. Setting the output parameter is done inside the JQuery change handler, which is executed asynchronously (so the Outsystems Message statement doesn't (yet) see it.
  4. The JQuery handler replaces the OutSystems onclick handler. I think this is the case because each subsequent time you click, the OutSystems handler isn't called at all (you can debug to verify).
  5. The alert is executed, because that's in the function that you bound to the JQuery change.

I'm not sure how to do what you want, you might want to check the documentation for the widget.

Solution

Thanks Kilian for your valuable time. 

I used input box and set the e.value to that input box using jquery. now it's working fine. 

Hi Suhas,

Great to hear you got it working. Happy coding!