Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
number class in Ajax loaded containers
10-03-2018, 01:14 PM, (This post was last modified: 10-03-2018, 01:26 PM by HDeriauFF.)
#1
number class in Ajax loaded containers
I'm trying to make the <inputs class="number"> from an ajax-loaded <div> behave the same way as they do in a regular page (preventing non-digits to be typed).

At the very bottom of MiscFunctions.js, there is
Code:
window.onload=initial;
, which is not working with a container that is loaded after the page page.

I embedded in my main page the following script which is derived from the initial() function:

Code:
$(document).on("keypress", '.number', function(event) {

var ds=document.getElementsByTagName("input");

for(i=0;i<ds.length;i++) {
    
     ds[i].onkeypress=myrTN;
         if(ds[i].className=="number") {
            ds[i].origonchange=ds[i].onchange;
            ds[i].newonchange=myrLocaleNumber;
            ds[i].onchange=function() {
                if(this.origonchange)
                    this.origonchange();
                this.newonchange();
            };
        }
}    

});

It works almost perfectly, with a little issue though: I am able to enter ONE non-digit (and one only) on any input I key in before the function kicks in and works correctly blocking all further attempts.

Any idea on how to make this work, the problem being to trigger the behavior on the very first key press.

Thank you for your "input" (no pun intended ;-)
I found the answer to my question: I replaced the event "keypress" by "keydown".
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)