0

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> 

2 Answers 2

2

Just add

var post = document.getElementById('postaladdress'); 

You keep trying to access the parameter value of the post object, but there is no such post object because you haven't defined it. If you add the above line after your definition of home, you should be set! It worked when I edited it on jsFiddle.

Sign up to request clarification or add additional context in comments.

1 Comment

That didn't completely work, but I found a solution. But thanks, that certainly helped me. Working version: jsfiddle.net/nnMYN/2
0

Try to put the javascript in function() {

<script type="text/javascript"> (function() { 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> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.