• 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: Populate text field from dropdown SOLVED

Populate text field from dropdown SOLVED 11 years 2 months ago #26696

First, let me say that I am using rev 44 because unfortunately I'm working on an antique Joomla 1.5.26 site.

I'm trying to get a dropdown to populate a text field. This form is to calculate the discount for each product. So when the user selects a product from the dropdown, I want the discount amount for that product to auto-populate the next field.

This way I can run a calculation on the fields to calculate the total discount.

This is the code I have thus far. I borrowed this from the Dynamic Drop-down Change Form:
<script type="text/javascript">
 
function dynamicPrice(parent,child){
 
	var parent_array = new Array();
 
	parent_array['99080 XSS'] = ['1146'];
 
	parent_array['112080 XSS'] = ['1349'];
 
	parent_array['115080 XSS'] = ['1559'];
 
	parent_array['116080 XSS'] = ['1896'];
 
	parent_array['120080 XSS'] = ['2160'];
 
	var thechild = document.getElementById(child);
 
	thechild.options.length = 0;
 
	var parent_value = parent.options[parent.selectedIndex].value;
 
	if (!parent_array[parent_value]) parent_value = '';
 
	thechild.options.length = parent_array[parent_value].length;
 
	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>
Then on the dropdown I've added this in the attributes:

onchange="dynamicPrice(this,'rebate_per');"

This code doesn't work. In the console, I get the following error "Uncaught TypeError: Cannot set property 'length' of undefined."


The first number is in the dropdown (e.g. 99080 XSS). I'm trying to get that second number ("1146" for example) to populate the text field.

Any help is appreciated. Thank you!
Last Edit: 11 years 2 months ago by danbrasic.
The administrator has disabled public write access.

Populate text field from dropdown SOLVED 11 years 2 months ago #26738

Solution:
<script type="text/javascript">
function dynamicPrice(parent,child)
{
var parent_array = new Array();
 
parent_array[''] = ['Please select a model'];
 
parent_array['99080 XSS'] = ['1146'];
 
parent_array['112080 XSS'] = ['1349'];
 
parent_array['115080 XSS'] = ['1559'];
 
parent_array['116080 XSS'] = ['1896'];
 
parent_array['120080 XSS'] = ['2160'];
 
 
var thechild = document.getElementById(child);	
 
var parent_value = parent.options[parent.selectedIndex].value;
 
 
if (!parent_array[parent_value]) parent_value = '';{	
thechild.value = parent_array[parent_value];
}
}
</script>

Then on the attributes of the dropdown ('rebate_per' is the field ID that the data from the dropdown goes in to):
onchange="dynamicPrice(this,'rebate_per');"
Last Edit: 11 years 2 months ago by danbrasic.
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!