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?
 
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
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.