#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Santa Barbara, CA, USA
    Posts
    11
    Rep Power
    0

    combine 3 fields with javascript


    I'm new to javascript and was hoping someone could help me with this issue. Couldn't find existing code.

    I have a simple form that requires the end user to submit their phone number. I would like to have 3 fields, area code, 3 digits and then final 4 digits in their own field. I would then like to combine the numbers into one variable before after submitting and before passing the action.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    NE Pa.
    Posts
    96
    Rep Power
    13

    Question why go thru all that headache?


    Why go thru the headache of three boxes & then adding them together into one field when you can do 1 input box, check it with a regular expression & then send in the one field? Sounds a lot easier huh?

    Make a text box lets say called phoneNum & then check it like this with JavaScript:

    function phoneTest() {
    with document.forms[0] {

    var pattern2 = /\d{3}\-\d{3}\-\d{4}/

    if (!pattern2.test(phoneNum.value) {
    alert("The phone number you entered is not in the proper format");
    phoneNum.focus();
    return false();
    }
    }
    }

    Of course dont be a jerk when setting up the input box, show them the format they are supposed to enter next to the input box.

IMN logo majestic logo threadwatch logo seochat tools logo