I have built a form requires a first address and second address. A user will have to fill out their address (first line, second line, zip etc) and it may be that this address is also the same for the second address fields (think postal and billing address). I have a radio button field that asks the question ‘is the second address the same as the first?’, if the user selects ‘yes’, how can I have the second address autopopulate with the data from the first address?
Probably a dead easy and stupid question, but I can’t work it out!
I suppose alternatively, is there an easy way of ‘blanking out’ the section of the form as opposed to autopopulating if the user selects ‘yes’?
You would use the onChange event from the radio button element to trigger an action. This generates a function (e.g. radio1_onChange) in your code window. There, you just copy the values from A to B, like
$w(“#Name2”).text= $w(“#Name1”).text (or whatever)
On your second question: yes, you can do that. Put the whole address block inside a Box. Then use .collapse() and .expand() on that box to take it away or show it.
If you run into the “it leaves a lot of open white space”-problem, search this forum for the “80/20 rule”.
Thanks Giri
So I decided that I wanted “address 2” to be the same as “address 1”, but I also wanted the form to remove the “address 1” details if the user deselected the “Same address?” radio button. Hopefully that makes sense…
My code does work and is below - any advice on cleaning this up would be greatly appreciated, as it seems quite cumbersome (do forgive me I have just started to teach myself javascipt):
export function sameAddress_change(event, $w) {
if ($w("#sameAddress").value === "Yes") {
$w("#address2Line1").value = $w("#address1Line1").value;
$w("#address2Line2").value = $w("#address1Line2").value;
$w("#address2City").value = $w("#address1City").value;
$w("#address2Region").value = $w("#address1Region").value;
$w("#address2PostCode").value = $w("#address1PostCode").value;
$w("#address2Country").value = $w("#address1Country").value;
}
else {
$w(“#address2Line1”).value = “”;
$w(“#address2Line2”).value = “”;
$w(“#address2City”).value = “”;
$w(“#address2Region”).value = “”;
$w(“#address2PostCode”).value = “”;
$w(“#address2Country”).value = “”;
}
}