I want to write a program, so I can type IP address numbers between 0 and 255. My code works in IE, but not in Firefox or Chrome.
function check(obj) {
var txt = obj.getAttribute("value");
txt = parseInt(txt);
if (txt > 255 || txt < 0) {
alert("must between 0 and 255");
obj.focus();
obj.select();
} else {
if (txt > 25) {
var next = parseInt(obj.getAttribute("id")) + 1;
if (next < 5) {
document.getElementById(next.toString()).focus();
}
}
}
}
<input type="text" maxlength="3" id="1" onkeyup="check(this);" />
<input type="text" maxlength="3" id="2" onkeyup="check(this);" />
<input type="text" maxlength="3" id="3" onkeyup="check(this);" />
<input type="text" maxlength="3" id="4" onkeyup="check(this);" />