By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,480 Members | 1,808 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,480 IT Pros & Developers. It's quick & easy.

Using a Checkbox to populate another field

P: 1
Hi all,

Trying to figure out how to use a checkbox in a form and have JavaScript populate another field. For instance, I have 2 fields:

DaytimePhone and EveningPhone and I have a checkbox that says "Check if evening phone is the same" and if you click that box, it should populate the evening field with the number entered in the DaytimePhone field. Does anyone know how to do that?
Sep 19 '06 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 15k+
P: 16,027
You can use onclick to call a function which populates the field, e.g.
Expand|Select|Wrap|Line Numbers
  1. <input type="checkbox" ... onclick="populate(this)">
Expand|Select|Wrap|Line Numbers
  1. function populate(checkbox) {
  2.     var daytime = document.getElementById("daytimeTel");
  3.     var evening = document.getElementById("eveningTel");
  4.     evening.value = daytime.value;
  5. }
You may also want to make use of the checked property of the checkbox so that the value is only copied if the checkbox is checked and not if it is unchecked.
May 13 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.