Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Feb 2006
    Posts
    138
    Thanks
    11
    Thanked 0 Times in 0 Posts

    How to concatenate form fields?

    I have the following inputs in an HTML form:

    <td>(<input class="phonetext" maxlength="3" name="phoneareacode" size="3" type="text" value="">)
    <input class="phonetext" maxlength="3" name="phoneexchange" size="3" type="text" value="">-
    <input class="phonetext" maxlength="4" name="phonenumber" size="4" type="text" value=""></td>

    I would like to combine all three of these values into one hidden field like this:

    <input type="hidden" id="phone" name="phone" value="?">

    With the? being the three values merged together...

    Thanks!

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You can do it with JS
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>&nbsp;</title>
    <script type="text/javascript">
    function combPhone()
    {
    	var areacode = document.forms[0].phoneareacode.value;
    	var exchange = document.forms[0].phoneexchange.value;
    	var phonenum = document.forms[0].phonenumber.value;
    	if(areacode.length = 3 && exchange.length == 3 && phonenum.length == 4)
    	{
    		document.forms[0].phone.value = areacode + exchange + phonenum;
    	}
    }
    </script>
    </head>
    
    <body>
    <form action="#" method="post">
    (<input class="phonetext" maxlength="3" name="phoneareacode" size="3" type="text">)
    <input class="phonetext" maxlength="3" name="phoneexchange" size="3" type="text">-
    <input class="phonetext" maxlength="4" name="phonenumber" size="4" type="text" onkeyup="combPhone()">
    <input type="hidden" id="phone" name="phone">
    </form>
    </body>
    </html>
    though its better to do it with a server side language on the server end because JS can be disabled.
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •