• 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: Is it possible? Dynamic Drop Down to Hidden Field

Is it possible? Dynamic Drop Down to Hidden Field 11 years 6 months ago #25298

  • ajprofitsinc
  • ajprofitsinc's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
  • Thank you received: 1
I am using the Dynamic Drop-Down change form example from demo.rsjoomla.com/dynamic-drop-down-change-form-example as a template to create a drop down list of departments that when a person chooses a department the form should populate a hidden field with an e-mail address associated with the selected department.

Can this be done? I am using the javascript code below that has been modified from the above example and I am using a drop down box (that has additional attributes= onchange="dynamic1(this,'HiddenField');" with a hidden field called HiddenField however the HiddenField always shows up as Empty in the submissions list. What am I doing wrong?

---
<script type="text/javascript">
function dynamic1(parent,child)
{
	var parent_array = new Array();
	// This is the default value
	parent_array[''] = ['Please select a department'];
	// All other elements
	// parent_array['PARENT NAME'] = ['CHILD 1','CHILD 2','CHILD 3','ETC'];
	parent_array['Department One'] = ['dep1@test.com'];
	parent_array['Department Two'] = ['dep2@test.com'];
 
	// Get the child
	var thechild = document.getElementById(child);
 
	// Remove all other options from the select element
	thechild.options.length = 0;
 
	// What value are we looking for ?
	var parent_value = parent.options[parent.selectedIndex].value;
 
	// No value found, use the default value
	if (!parent_array[parent_value]) parent_value = '';
 
	// Set the correct length
	thechild.options.length = parent_array[parent_value].length;
 
	// Add the options
	for(var i=0;i<parent_array[parent_value].length;i++)
	{
		thechild.options[i].text = parent_array[parent_value][i];
		thechild.options[i].value = parent_array[parent_value][i];
	}
}
</script>
The administrator has disabled public write access.

Is it possible? Dynamic Drop Down to Hidden Field 11 years 6 months ago #25368

  • ajprofitsinc
  • ajprofitsinc's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
  • Thank you received: 1
I submitted this to RSJOOMLA support and they replied back with the following that I have tested and found to work as desired.

RSJOOMLA SUPPORT STATED:
To use the script in question with a hidden field you will need to perform certain modifications, due to the way Javascript handles hidden fields.
<script type="text/javascript">
function dropdownToInput(parent,child)
{
var parent_array = new Array();
// This is the default value
parent_array[''] = ['Please select a department'];
// All other elements
// parent_array['PARENT NAME'] = ['CHILD 1','CHILD 2','CHILD 3','ETC'];
parent_array['Department One'] = ['dep1@test.com'];
parent_array['Department Two'] = ['dep2@test.com'];
 
// Get the child
var thechild = document.getElementById(child);
 
// What value are we looking for ?
var parent_value = parent.options[parent.selectedIndex].value;
 
// No value found, use the default value
if (!parent_array[parent_value])
parent_value = '';
 
// Add the options
thechild.value = parent_array[parent_value][0];
for(var i = 1; i < parent_array[parent_value].length; i++)
{
thechild.value += ", " + parent_array[parent_value][i];
}
}
</script>

Please also remember to change the onchange trigger on your dropdown field to:

onchange="dropdownToInput(this, 'HiddenField');"
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!