<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>EJERCICIO_002</title> </head> <body> <fieldset> <legend>Billing Information</legend> <p> <label> Postal Address:<br> <input onclick=setHomeAddress() name="postaladdress" id="postaladdress"></input> </label> </p> <p> Home Address:<br> <label> <input " type="checkbox" name="homepostalcheck" id="homepostalcheck"> Same as above </label> <br> <input name="homeaddress" id="homeaddress"></input> </p> </fieldset> <script> function setHomeAddress(){ document.querySelector('#postaladdress').addEventListener('change', (e)=>{ alert(e.target.value); }); document.querySelector('#homeaddressdiv').addEventListener('click', ()=>{ if(document.querySelector('#homepostalcheck').checked){ document.querySelector('#homeaddress').disabled = true; document.querySelector('#homeaddress').value = document.querySelector('#postaladdress').value; }else{ document.querySelector('#homeaddress').disabled = false; document.querySelector('#homeaddress').value = ""; } }); } </script> </body> </html>