Skip to main content
MarkWalsh
Inspiring
October 17, 2017
Question

Keystroke script: get current updated value

  • October 17, 2017
  • 1 reply
  • 1074 views

I'm trying to validate a keystroke entry based on the text already entered. I can get the value before the change was made, but I can't figure out how to tell the value that includes the changes (i.e. I need to accept or reject the keystroke based on the entire updated field contents).  I'm sure I've done this in the past, but I can't find an example of it.

Is there an event property which shows the full value with changes included?

This topic has been closed for replies.

1 reply

Inspiring
October 17, 2017

During keystroke entry one can use the "change" property of the event object.

MarkWalsh
MarkWalshAuthor
Inspiring
October 17, 2017

Thanks, but I don't think that's what I'm looking for.

What I need is if the field contains '456', and the user selects the '56' and types '9', I want (what will be) the new value '49' The change value seems to be only the entered character (9 in this case).

Is what I'm looking for not available directly? I am guessing I can get what I need by checking the event selection values, and parse the current value with the change value, but I was hoping there was a property I could access which has the value.

MarkWalsh
MarkWalshAuthor
Inspiring
October 17, 2017

So, this is what I ended up with to check for the current change value, and it seems to work as I expected.

function getCurrentChangeValue() {

  var s = event.selStart

  var e = event.selEnd

  var value = event.value

  var c = event.change

  value = value.substr(0, s) + c + value.substr(e)

  return value

}

If there is a built in property to do this, I'd rather use that.