I have a script that validates phone numbers, adding - where needed and auto-advancing after each dash. It works fine, but I need to make the last line dynamic.
function autoPhoneNum(theform,thefield) {
num = eval("window.document."+theform+"."+thefield+".value"
num = num.replace(/^[01]+/, '').replace(/[^0-9]/g, '');
num = num.slice(0,3) + (num.length > 3 ? "-" + num.slice(3,6) : "" + (num.length > 6 ? "-" + num.slice(6,10) : ""
window.document.AddClient.HomePhone.value = num;
}
Right now, the second line makes "num" dynamic, but for the last line I have to hard code the name of the element whose value I am setting. How do I make this field dynamic so I can use the script multiple times on a page?
Thanks,
function autoPhoneNum(theform,thefield) {
num = eval("window.document."+theform+"."+thefield+".value"
num = num.replace(/^[01]+/, '').replace(/[^0-9]/g, '');
num = num.slice(0,3) + (num.length > 3 ? "-" + num.slice(3,6) : "" + (num.length > 6 ? "-" + num.slice(6,10) : ""
window.document.AddClient.HomePhone.value = num;
}
Right now, the second line makes "num" dynamic, but for the last line I have to hard code the name of the element whose value I am setting. How do I make this field dynamic so I can use the script multiple times on a page?
Thanks,