LIVE CODE: http://jsfiddle.net/nnMYN/
I have to “automatically copy the postal address to the home address field if a user checks the “Same as above” checkbox. In addition to this, we’ll disable the home address field when the checkbox is checked.” (from here) What am I doing wrong?
<html>
<head>
</head>
<body>
<form>
<fieldset>
<legend>Billing Information</legend>
<p>
<label>
Postal Address:<br>
<textarea name="postaladdress" id="postaladdress"></textarea>
</label>
</p>
<p>
Home Address:<br>
<label>
<input type="checkbox" name="homepostalcheck" id="homepostalcheck">
Same as above
</label>
<br>
<textarea name="homeaddress" id="homeaddress"></textarea>
</p>
</fieldset>
</form>
<script type="text/javascript">
var loc = document.getElementById('homepostalcheck');
var home = document.getElementById('homeaddress');
loc.onclick = !loc.checked ? function() {home.disabled = true; home.value = post.value; alert(post.value);} : function() {home.disabled = false; home.select();};
</script>
</body>
</html>
Just add
You keep trying to access the parameter
valueof thepostobject, but there is no suchpostobject because you haven’t defined it. If you add the above line after your definition ofhome, you should be set! It worked when I edited it on jsFiddle.