Js Ejercicio 2

parent b214e436
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Billing</title>
</head>
<body>
<fieldset>
<legend>Billing Information</legend>
<p>
<label>
Postal Address:<br>
<input name="postaladdress" id="postaladdress"></input>
</label>
</p>
<p id="homeaddressdiv">
Home Address:<br>
<label>
<input type="checkbox" name="homepostalcheck" id="homepostalcheck">
Same as above
</label>
<br>
<input name="homeaddress" id="homeaddress"></input>
</p>
</fieldset>
</body>
<script>
const setHomeAddress = ()=>{
document.querySelector('#postaladdress')
.addEventListener('change', (e)=>{
alert(e.target.value);
});
document.querySelector('#homeaddressdiv')
.addEventListener('click', ()=>{
const addressInput = document.querySelector('#homeaddress');
const checkbox = document.querySelector('#homepostalcheck');
const postalInput = document.querySelector('#postaladdress');
if(checkbox.checked){
addressInput.disabled = true;
addressInput.value = postalInput.value;
}else{
addressInput.disabled = false;
addressInput.value = "";
}
});
}
setHomeAddress();
</script>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment