Forum Moderators: open
<input type=\"text\" name=\"shutoff\" value=".$shutoff." onkeyup =\"validField(this.value)\">
function validField(txtfield) {
if (txtfield.length <= 10)
{
var checklist = '0987654321';
//compare last entered char to checkList string
var x = checkList.indexOf(txtfield.charAt(txtfield.length-1));
if(x == -1) { //if character is not numeric, delete last character
txtfield = txtfield.substring(0, txtfield.length -2);
this.value = txtfield;
//i dunno how to do the above in the right way, this is trying to
//set the textbox value to itself minus invalid character
//i'm assuming 'this' refers to the textbox object that called the
//function
}
else { //add slash after day
if (txtfield.length == 2) {
txtfield = txtfield + "/";
this.value = txtfield;}
else if (txtfield.length == 5) { //add slash after month
txtfield = txtfield + "/";
this.value = txtfield;}
}
}
else {alert("Please keep the date format, which is: dd/mm/yyyy!");}
}