Skip to main content
Inspiring
January 19, 2010
Answered

Creating 3 part telephone input

  • January 19, 2010
  • 2 replies
  • 546 views

Hi. Does anyone have an idea on the best way to change a variable called "NPHONE" into a 3 part telephone input instead of one input?

My problem is this is on a very very large site and is used in so many places that changing the database to fields such as "nphone1", "nphone2", "nphone3" is not feasible.

I am wondering if there is a way to take change what is already there into something like this:

<input type="text" maxlength="3" name="nphone1"> - <input type="text" maxlength="3" name="nphone2"> - <input type="text" maxlength="4" name="nphone1">

Then possibly set the existing form field name of "NHPONE" to equal the 3 form fields above?

I think this code below is setting another variable called "NPHN1" to equal what the original "NPHONE" variable was.

<cfset structinsert(arguments.formData,'NPHN1',arguments.formData.NPHONE)>

Would there be a way to swap out the above line of code to set "NPHN1" to equal my 3 new phone fields?


Thanks in advance for your time.

    This topic has been closed for replies.
    Correct answer TiGGi

    It's possible to break your phone string into a comma delimited list and save into that same db field so somethng  like 800,555,5555 instad of 800-555-5555. This way you can loop through the list when displaying.  Also if you use form to save this data u can use same form field name for all 3 and it will automaticaly pass it in comma delimited format.

    for the form you would do

    <input type="text" maxlength="3" name="nphone"> - <input type="text" maxlength="3" name="nphone"> - <input type="text" maxlength="4" name="nphone">

    2 replies

    TiGGiCorrect answer
    Inspiring
    January 19, 2010

    It's possible to break your phone string into a comma delimited list and save into that same db field so somethng  like 800,555,5555 instad of 800-555-5555. This way you can loop through the list when displaying.  Also if you use form to save this data u can use same form field name for all 3 and it will automaticaly pass it in comma delimited format.

    for the form you would do

    <input type="text" maxlength="3" name="nphone"> - <input type="text" maxlength="3" name="nphone"> - <input type="text" maxlength="4" name="nphone">

    brianismAuthor
    Inspiring
    January 20, 2010

    Thanks. I didn't realize that you could split up input like that with the same field name.  That should solve my problem!

    Inspiring
    January 19, 2010

    I'd concatonate them on the action page myself.