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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format a text box that is populated by a Select box

Status
Not open for further replies.

scc

Programmer
Apr 30, 2001
218
US
I have several text boxes that are populated automatically when a user chooses a Selection in a Select box:

function putValue(sValue)
{
//used to capture the FirstName, LastName,
//and phone number of the Case Manager that
//the user selects
sValue = sValue.split('|');
document.forms[1].CMFirstName.value = sValue[0];
document.forms[1].CMLastName.value = sValue[1];
document.forms[1].CMPhone.value = sValue[2];
document.forms[1].CMDisplayPhone.value = sValue[2];
}


One of the text boxes (CMDisplayPhone) needs to be formatted to be read like a phone number for Display to the User (i.e. 123-456-7890 ).

How can I do this?

TIA
 
<script language=&quot;javascript&quot;>

function formatNumber( n )
{
var areaCode = n.substring(0, 3)
var prefix = n.substring(3, 6)
var num = n.substring(6, 10)
var phoneNumber = areaCode + &quot;-&quot; + prefix + &quot;-&quot; + num
return phoneNumber
}

var n = '1234567890'
document.write( formatNumber( n ) )

</script>
 
Okay, so say I have an input box named displayNumber, how would I dynamically format the value when the user clicks on the Selection shown in my original post above? The selection box would use the onchange event to get the values for several input boxes (FirstName, LastName and Phone), but what event would I use to call the function to format the input box for the Phone?:

<input type=&quot;text&quot; name=&quot;displayNumber&quot; value=&quot;&quot; disabled=&quot;disabled&quot;>


Or here's another need, say I have a value from a recordset and now I need to format that value in the input box:

<input type=&quot;text&quot; name=&quot;PCPPhone&quot; maxlength=&quot;15&quot; disabled=&quot;disabled&quot; value=<%= rs.Fields(&quot;Phone&quot;)%>>

How would I call the function to format this value in the input box?

That's where I'm stumped. Since the user is not typing the values in for these two text boxes, I'm not sure how to go about triggering the function to format the values.

Thanks!
 
Are you wanting this in javascript or ASP? It's sounding like you really want this in asp.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top