Hello and welcome to our community! Is this your first visit?
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
    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...


  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    In a place far, far away...
    Thanked 1,043 Times in 1,019 Posts
    You can do it with JS
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <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;
    <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">
    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