HTML Question

auto input data depended what i input in html form

Please help me

how to auto input data depended what i input in html form.


in a form have a two field "CITY" AND "ZIPCODE"
i want when anyone type any zip code on zip code field then the city field auto full up

more example:

input zipdcode="1050" auto input in city="dhaka"
input zipcode="3000" auto input in city="barisal"
input zipcode="5000" auto input in city="khulna"

just like this here is a picture

Answer Source

Checkout the following

const zipInput = document.querySelector('#zip'),
      cityInput = document.querySelector('#city'),
      zipCityMap = {
          1050: 'dhaka',
          3000: 'barisal',
          5000: 'khulna'

zipInput.addEventListener('keyup', myKeyup);

function myKeyup(e){
   const city = zipCityMap[this.value];
     cityInput.value = city;
   } else {
     cityInput.value = '';
<input id="zip" value=""/>
<input id="city" value="" />

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download