- This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- The forum ‘Other’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Hey guys,
I’m trying to create an input form that inputs “-” after 3 character. Like this “123-456-789”.
Everything is all good, except when I type inside the input field, the word “undefined” shows up after 3 characters.
Hope someone helps me.
This is what I have:
$(“.taxidno”).live(‘keypress’, function () {
var theEvent = window.event;
var key = theEvent.keyCode || theEvent.which;
key = String.fromCharCode(key);
var regex = /^[a-zA-Z0-9]*$/;
if (!regex.test(key)) {
theEvent.returnValue = false;
if (theEvent.preventDefault) theEvent.preventDefault();
}
var str = $(this).val().replace(/-/g, '');
var newVal2 = '';
var returnVal = '';
if (str.length > 19) {
return false;
}
if (str.length != 0 && str.length % 3 == 0) {
for (var i = 0; i < str.length; i++) {
newVal2 += str[i];
if (newVal2.length != 0 && newVal2.length % 3 == 0) {
returnVal += newVal2 + '-';
newVal2 = '';
}
}
$(this).val(returnVal);
}
});
It works for me – but only after changing the first line, change “live” to “on” (live is deprecated).
Hello Senff, I tried to change it to “on” but this error occur Object doesn’t support property or method ‘on’ I guess the problem is on my browser, im using Internet Explorer 7 but when I run it on IE11 it works. Anyway thanks for the response.