Click here to Skip to main content
15,903,632 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

Iam trying to capture a persons current and permanent address.

If the current and permanent address are the same, it means there is no need to enter the same information twice. Iam using a checkbox to indicate that the addresses are the same.

If the checkbox gets checked, I would like to put the current address into the permanent address controls. How do I do that?



Thanks in Advance
Posted

on the click event you can assign the value of one control to another control

like on
Check1_Click()
{
text2.text = text1.text;
}
 
Share this answer
 
You're going to want to use JavaScript. jQuery is super easy to include in your page and makes the values stoopid-easy to copy.

For example, if you have a button with an ID of make-same, you could do something like this:

JavaScript
$(function(){
    $('#make-same').click(function(){
      // ...do this for each line
      $('#permanent-address-line-1').val($('#current-address-line-1').val());
    });
});


There's actually two parts to this, both using the .val() function.

.val() will return the value of the control if you don't pass any params in, and it will set the value of the control if you do. So here, we're getting the current ($('#current-address-line-1').val()) and using that as the value for the permanent address.

As commented, you'll need to do one per line. There are other tricks with ID filtering, but that's over-complicating the scenario.

EDIT: if you want to clear the boxes on a second click, you can also handle state of the checkbox with jQuery fairly easily.
JavaScript
if($("#isAgeSelected").is(':checked'))
 {
   // copy the addresses
 }
else
 {
   // set the values to blank with .val('')
 }            


Cheers.
 
Share this answer
 
v2
Call this function on the Chechbox like:



XML
function checkabove()
{
  if(document.getElementById("chkadd").checked)
  {
    document.getElementById('<%=ddlsecprefix.ClientID %>').value =  document.getElementById('<%=ddlprefix.ClientID%>').value
    document.getElementById('<%=txtsecfirstname.ClientID%>').value=document.getElementById('<%=txtFname.ClientID%>').value;
    document.getElementById('<%=txtseclastname.ClientID%>').value=document.getElementById('<%=txtLname.ClientID%>').value;
    document.getElementById('<%=txtadd1.ClientID%>').value=document.getElementById('<%=txtAddress1.ClientID%>').value;
    document.getElementById('<%=txtadd2.ClientID%>').value=document.getElementById('<%=txtAddress2.ClientID%>').value;
    document.getElementById('<%=txtseccity.ClientID%>').value=document.getElementById('<%=txtCity.ClientID%>').value;
    document.getElementById('<%=txtseczip.ClientID%>').value=document.getElementById('<%=txtZipCode.ClientID%>').value;
    document.getElementById('<%=statesec.StateCombo.ClientID%>').value=document.getElementById('<%=State1.StateCombo.ClientID%>').value;
  }

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900