NetTalk Central

Author Topic: Changing field value in onchange event  (Read 2098 times)

Ubaidullah

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Changing field value in onchange event
« on: September 26, 2020, 01:00:06 AM »
Hi,

I have a slider control in a NetWebForm and want to display a value in another field based on the value in the slider control.

For now, I have a field named LOC:DispValue in the NetWebForm.

I have added the following code to the onchange event of the slider control.

'SetSessionValue(''LOC:DispValue'', this.value+''A'')'

The LOC:DispValue field will display 1A, 2A, 3A when the slider control is 1,2,3 respectively.

But, when the slider control is at 2, LOC:DispValue will still be showing 1A. It's always lagging by a number.

What am I doing wrong ?





bshields

  • Sr. Member
  • ****
  • Posts: 392
    • View Profile
    • Inhabit
    • Email
Re: Changing field value in onchange event
« Reply #1 on: September 26, 2020, 04:43:32 AM »
From memory you might want "oninput" not "onchange". "onchange" waits for a "loss of focus" to occur before firing the event. "oninput" should fire the event immediately.

But frankly, i'm guessing.

Ubaidullah

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Re: Changing field value in onchange event
« Reply #2 on: September 27, 2020, 01:32:24 AM »
Thanks for the suggestion.

I put this in the onchange field:

'" oninput="SetSessionValue(''LOC:DispValue'', this.value+''ABC'')'

But I am not seeing any change to the LOC:DispValue field.

So, what's the correct way to add code to "oninput" ?


Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11181
    • View Profile
Re: Changing field value in onchange event
« Reply #3 on: September 27, 2020, 11:49:55 PM »
Hi Ubaidullah,

You are mixing up your concepts of client side and server side;

>> I put this in the onchange field:
>> '" oninput="SetSessionValue(''LOC:DispValue'', this.value+''ABC'')'

so that's javascript, and triggers when the field changes. SetSessionValue will send a new session value to the server.
(it won't refresh anything on the screen, because that's not what SetSessionValue does)

I suspect you want this code on the _server side_ so that it executes when the slider changes. And then the slider control updates the DispValue field (as I suspect you have already set it there to reset...)

cheers
Bruce

Ubaidullah

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Re: Changing field value in onchange event
« Reply #4 on: September 28, 2020, 04:01:21 AM »
Hi Bruce,

Thanks for your reply.

I am trying to give immediate feedback to the user which is why I want to have javascript code that can run without waiting for reply from the server.

I really don't need to send any value back to the server.
So, now I removed SetSessionValue, and just used normal javascript code. This works for onchange, but I cannot seem to get it to work for oninput.

So, when I have this in the onchange field, it works:
'updateDisp(this.value)'

But when I put this, it doesn't work:
'" oninput="updateDisp(this.value)'

I have this in custom.js :


function updateDisp(pVal) {

 document.getElementById("updateitems_loc__dispvalue2_value_div").innerHTML = pVal+"abc";

}




« Last Edit: September 28, 2020, 04:03:49 AM by Ubaidullah »

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11181
    • View Profile
Re: Changing field value in onchange event
« Reply #5 on: September 29, 2020, 06:13:01 PM »
debug in the normal way for javascript.
ie - make sure the code runs (use console.log) - inspect the code to make sure it's where you think it is, and so on.

cheers
Bruce