Send input data on change from HTML to Client Script in Service Portal Widget

mballinger
Mega Guru

Hello,

We have a service portal widget that I need to enhance. One of the things I need to do is send input data from the HTML to the Client Script without any button click. Once the input data has been populated (text entry) and the user clicks on the next input field, that data should be readily available on the client side for further processing.

What I have so far but is not working:

HTML:

<label>Enter Number of Occurrences</label><br/>
<input id="input-num" ng-model="numOccurences" onchange="numOcc()"><br/>

Client Script:

function($scope, $sce, spModal, $rootScope, $window, $filter,spUtil) {
   var c = this;

   c.numOcc = function() {
      var occurences = document.getElementById('input-num').value;
      alert(occurences); //This is not alerting any value
   }
}

Thanks!

 

3 REPLIES 3

Tom Sienkiewicz
Mega Sage

try something like this.

not tested though, might need to be tweaked a bit.

 

<input id="input-num" ng-bind="data.numOccurences" onchange="numOcc()"><br/>

 

c.numOcc = function() {

alert($scope.data.numOccurences);  }

 

AbhishekBaratam
Kilo Contributor

Were u able to find how to do this correctly

Markus Kraus
Kilo Sage

Old Thread, but from first glance this actually looks okay, however the key error is that onchange="numOcc()" is incorrect. It should be ng-change="c.numOcc()" (granted, that the widget is configured with controllerAs = c - which is the default configuration).