Form populate two form fields with one input

I have a scenario where I have a zip_code and billing_zip_code form fields in a form.  How do I autopopulate billing_zip_code with the same data zip_code is entered with initially?
pda4meAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nap0leonCommented:
Presuming it's a text input...

use the onchange event to set the billing zip to the value of the home zip field

for example:
Zip Code: <input type="text" id="homeZip" name="homeZip" onchange="javascript:setBillingZip();"/>
<br/>Billing Zip: <input type="text" id="billingZip" name="billingZip"/>
<script>
function setBillingZip(){
  document.getElementById("billingZip").value = document.getElementById("homeZip").value;
}
</script>

Open in new window

0
StingRaYCommented:
By nap0leon's reply, if you want to change only when billingZip is empty, you can do it by:

Zip Code: <input type="text" id="homeZip" name="homeZip" onblur="javascript:setBillingZip();"/>
<br/>Billing Zip: <input type="text" id="billingZip" name="billingZip"/>
<script>
function setBillingZip(){
  if (document.getElementById("billingZip").value == "") {
    document.getElementById("billingZip").value = document.getElementById("homeZip").value;
  }
}
</script>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pda4meAuthor Commented:
How do I combine this to make it work?

<input type="text" name="zipcode" onkeypress="return numbersonly(event)" id="zipcode" onBlur="showUser(this.value)," onchange="javascript:setzip();"/>
0
pda4meAuthor Commented:
never mind, found the bug!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.