• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Can't Get Auto-populate Javascript to Work

Can't Get Auto-populate Javascript to Work 11 years 10 months ago #23845

Hi,

I'm trying to implement a simple javascript in one of my forms, which will auto populate the mailing address fields from an office address, if the user clicks a checkbox. I cannot for the life of me get the script to work. I click the checkbox and nothing happens.

The script itself is almost identical to the one described here.

The form consists of:

Name = CompanyStreet
Type = Textbox
Caption = Company Street
Attributes = style="width:400px;"

Name = nomailingaddress
Type = Checkbox Group
Items = asabove|Same as Office Address
Attributes = onchange="copyoffice()"

Name = Address2
Type = Textbox
Caption = Street
Attributes = style="width:400px;"

In the "Javascript" field in Properties:
<script type="text/javascript">
function copyoffice()
{
	if (document.getElementById('nomailingaddress').checked) document.getElementById('Address2').value = document.getElementById('CompanyStreet').value;
		else document.getElementById('Address2').value = '';
}
</script>

Is there something obvious I'm doing wrong? I'm fairly new to both RSForm! and Javascript, and I'm completely stumped.
The administrator has disabled public write access.

Can't Get Auto-populate Javascript to Work 11 years 10 months ago #23847

  • adrianp
  • adrianp's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 631
  • Thank you received: 146
Hello,

The id's of the checkboxes of a checkbox group in RSForm!Pro are formed from the checkbox group name and a number, starting from 0.

Try using this instead:
<script type="text/javascript">
function copyoffice()
{
	if (document.getElementById('nomailingaddress0').checked) document.getElementById('Address2').value = document.getElementById('CompanyStreet').value;
		else document.getElementById('Address2').value = '';
}
</script>

Notice that "nomailingaddress0" has a zero now. You should also change the trigger from onchange into onclick:

onclick="copyoffice();"
This is not official customer support. To receive your support, submit a support ticket here.
The administrator has disabled public write access.
The following user(s) said Thank You: illuminatus

Can't Get Auto-populate Javascript to Work 11 years 10 months ago #23848

Thanks. Working perfectly now.
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!