dharkangel
MIS
Hi,
I am using the following javascript and html to format telephone numbers with appropriate dashes (xxx-xxx-xxxx). The script works fine in doing that but I receive an error on my action page asking for the 'BusinessPhone' variable. somehow it seems the javascript code is keeping the variable from being passed.
does anyone see anything wrong?. For those not familiar with cold Fusion, I am using it which is why there is a cfform tag instead of form.
--------------------------------
<cfform action="fx_actions.cfm" method="post" name="mainform">
<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>
---------------------------
html code:
The field: <input type="text" size="20" name="BusinessPhone" id="id_phone">
The submit button that activates the function: <INPUT type="submit" name="Register" value="Register" id="id_function" onclick="return addDashes()">
I am using the following javascript and html to format telephone numbers with appropriate dashes (xxx-xxx-xxxx). The script works fine in doing that but I receive an error on my action page asking for the 'BusinessPhone' variable. somehow it seems the javascript code is keeping the variable from being passed.
does anyone see anything wrong?. For those not familiar with cold Fusion, I am using it which is why there is a cfform tag instead of form.
--------------------------------
<cfform action="fx_actions.cfm" method="post" name="mainform">
<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>
---------------------------
html code:
The field: <input type="text" size="20" name="BusinessPhone" id="id_phone">
The submit button that activates the function: <INPUT type="submit" name="Register" value="Register" id="id_function" onclick="return addDashes()">