Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with sending variable to action page

Status
Not open for further replies.
Joined
Sep 25, 2002
Messages
159
Location
US
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()">
 
You are disabling the field before you submit, and therefore the value doesn't get passed. Any reason you're doing this?

Code:
<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>

-kaht

[small] <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
[banghead] [small](He's back)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top