Update form value

Posted on 2009-02-17
Last Modified: 2013-11-19
I have the field ATAccName, when the user leaves this blank I want to populate it with the value from fields ATConFName and ATConLName. I have seen this done before. Any help you can provide is appreciated. I have to do this with several fields but if you can help me with this one I can do the others.

Thank you in advance.
<form id="ATForm" onsubmit="return Validate(this)" action="" method="post">

    <table cellspacing="0" cellpadding="0" width="500">



                <td>Company (If not a company, use first and last name)<span style="color: red"><font size="2"> *</font></span></td>

                <td><input id="ATAccName" style="width: 250px" type="text" maxlength="200" name="ATAccName" /> </td>



                <td>First Name<span style="color: red"><font size="2"> *</font></span></td>

                <td><input id="ATConFName" style="width: 250px" type="text" maxlength="40" name="ATConFName" /> </td>



                <td>Last Name<span style="color: red"><font size="2"> *</font></span></td>

                <td><input id="ATConLName" style="width: 250px" type="text" maxlength="40" name="ATConLName" /> </td>



                <td>Phone #<span style="color: red"><font size="2"> *</font></span></td>

                <td><input id="ATAccPhone" style="width: 250px" type="text" maxlength="50" name="ATAccPhone" /> </td>



                <td>Address<span style="color: red"><font size="2"> *</font></span></td>

                <td><input id="ATConAddr1" style="width: 250px" type="text" maxlength="128" name="ATConAddr1" /> </td>



                <td>Suite / Apt #<span></span></td>

                <td><input id="ATConAddr2" style="width: 250px" type="text" maxlength="128" name="ATConAddr2" /> </td>



                <td>City<span style="color: red"><font size="2"> *</font></span></td>

                <td><input id="ATConCity" style="width: 250px" type="text" maxlength="32" name="ATConCity" /> </td>



                <td>State<span style="color: red"><font size="2"> *</font></span></td>

                <td><select id="ATConState" size="1" name="ATConState" unselectable="off">

                <option selected="true">Select One</option>

                <option value="NA">Non Applicable</option>

                <option value="AL">Alabama</option>

                <option value="AK">Alaska</option>

                <option value="AB">Alberta</option>

                <option value="AS">American Samoa</option>

                <option value="AZ">Arizona</option>

                <option value="AR">Arkansas</option>

                <option value="BC">British Columbia</option>

                <option value="CA">California</option>

                <option value="CO">Colorado</option>

                <option value="CT">Connecticut</option>

                <option value="DE">Delaware</option>

                <option value="DC">District of Columbia</option>

                <option value="FL">Florida</option>

                <option value="GA">Georgia</option>

                <option value="HI">Hawaii</option>

                <option value="ID">Idaho</option>

                <option value="IL">Illinois</option>

                <option value="IN">Indiana</option>

                <option value="IA">Iowa</option>

                <option value="KS">Kansas</option>

                <option value="KY">Kentucky</option>

                <option value="LA">Louisiana</option>

                <option value="ME">Maine</option>

                <option value="MB">Manitoba</option>

                <option value="MD">Maryland</option>

                <option value="MA">Massachusetts</option>

                <option value="MI">Michigan</option>

                <option value="MN">Minnesota</option>

                <option value="MS">Mississippi</option>

                <option value="MO">Missouri</option>

                <option value="MT">Montana</option>

                <option value="NE">Nebraska</option>

                <option value="NV">Nevada</option>

                <option value="NB">New Brunswick</option>

                <option value="NH">New Hampshire</option>

                <option value="NJ">New Jersey</option>

                <option value="NM">New Mexico</option>

                <option value="NY">New York</option>

                <option value="NF">Newfoundland</option>

                <option value="NC">North Carolina</option>

                <option value="ND">North Dakota</option>

                <option value="MP">Northern Mariana Island</option>

                <option value="NT">Northwest Territories</option>

                <option value="NS">Nova Scotia</option>

                <option value="OH">Ohio</option>

                <option value="OK">Oklahoma</option>

                <option value="ON">Ontario</option>

                <option value="OR">Oregon</option>

                <option value="OT">Outside North America</option>

                <option value="PW">Palau</option>

                <option value="PA">Pennsylvania</option>

                <option value="PE">Prince Edward Island</option>

                <option value="PQ">Quebec</option>

                <option value="RI">Rhode Island</option>

                <option value="SK">Saskatchewan</option>

                <option value="SC">South Carolina</option>

                <option value="SD">South Dakota</option>

                <option value="TN">Tennessee</option>

                <option value="TX">Texas</option>

                <option value="UT">Utah</option>

                <option value="VT">Vermont</option>

                <option value="VA">Virginia</option>

                <option value="WA">Washington</option>

                <option value="WV">West Virginia</option>

                <option value="WI">Wisconsin</option>

                <option value="WY">Wyoming</option>

                <option value="YT">Yukon Territory</option>

                </select> </td>



                <td>Zip Code<span style="color: red"><font size="2"> *</font></span></td>

                <td><input id="ATConZip" style="width: 250px" type="text" maxlength="16" name="ATConZip" /> </td>



                <td>Note Description<span style="color: red"><font size="2"> *</font></span></td>

                <td><input id="ATNotDetail" style="width: 250px" type="text" maxlength="1000" name="ATNotDetail" /> </td>



                <td><br />




                <td><input id="btnSubmit" type="submit" value="Submit" /> </td>





Open in new window

Question by:jimseiwert
    LVL 5

    Expert Comment

    Not sure what is you server-side language, but you can check value on the server side, and concatenate ATConFName and ATConLName if it's empty.

    Also, you may do this on onSUbmit javascript form event handler .
    LVL 2

    Author Comment

    this form is doing a postback. How would I do the onsubmit javascript with out interfering on the postback?
    LVL 2

    Author Comment

    everything is being done with html
    LVL 19

    Expert Comment

    try something like this
    function check () {
          if (document.getElementById('ATAccName').value ==0) {
                var z  = document.getElementById('ATAccName').value;
                var x  = document.getElementById('ATConFName').value;
                var y  = document.getElementById('ATConLName').value;
          document.getElementById('ATAccName').value = X+y
    LVL 15

    Accepted Solution

    in your Validate(myform) function add

    myform.ATAccName.value = myform.ATConFName.value + " " +  myform.ATConLName.value;

    just simple as that:)

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
    Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now