dharkangel
MIS
I have the following code that I am trying to use to automatically place dashes between the area code and numbers of my phone numbers. It works fine, except that when I do not type the right number and my alert box appears, when I click ok, it forwards me to the action page. How do I make it stay on this page when I click ok on the alert box? I thought putting return false would do the trick but it doesn't.
<script language="JavaScript">
//Telephone Script
function addDashes(){
var phone = document.forms["mainform"].id_phone.value;
var path = document.forms["mainform"].id_phone;
var areacode = phone.substring(0,3);
var prefix = phone.substring(3,6);
var lastfour = phone.substring(6,10);
var newnumber = areacode + "-" + prefix + "-" + lastfour;
if(phone.length == 10)
{
path.value = newnumber;
path.disabled =true;
}
else{
alert("Please enter a valid telephone number");
path.focus()
return false
}
}
</script>
<script language="JavaScript">
//Telephone Script
function addDashes(){
var phone = document.forms["mainform"].id_phone.value;
var path = document.forms["mainform"].id_phone;
var areacode = phone.substring(0,3);
var prefix = phone.substring(3,6);
var lastfour = phone.substring(6,10);
var newnumber = areacode + "-" + prefix + "-" + lastfour;
if(phone.length == 10)
{
path.value = newnumber;
path.disabled =true;
}
else{
alert("Please enter a valid telephone number");
path.focus()
return false
}
}
</script>