• 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: Need default values for Dynamic Drop-down change

Need default values for Dynamic Drop-down change 15 years 4 months ago #9315

I have the dynamic dropdown (aka chained select list) working. However, I need to have a default value on page load. This works fine until I try to come back to the first value.

For example, the first dropdown is for Division and the second dropdown is for Recipient.

The default Division is "Corporate". When I select anothe division, it's fine, it changes the Recipient list. However, when I try to go back to Corporate, I no longer get a dropdown in the Recipient list.

Here is my code:
Division field:
 
|Corporate
Sales
Research
 
Recipient field:
 
|Select one...
John Doe
Mary Smith
 
 
Script:
 
<script type="text/javascript">
function dynamic1(parent,child)
{
	var parent_array = new Array();
	// This is the default value
	//parent_array[''] = ['Corporate'];
	parent_array[''] = ['Select Division'];
	// All other elements
	// parent_array['PARENT NAME'] = ['CHILD 1','CHILD 2','CHILD 3','ETC'];
	parent_array['Corporate'] = ['John Doe','Mary Smith'];
	parent_array['Sales'] = ['Jane Doe','John Smith'];
	parent_array['Research'] = ['Bugs Bunny','Minnie Mouse'];
 
	// 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.

Re:Need default values for Dynamic Drop-down change 15 years 4 months ago #9324

  • andreic
  • andreic's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 745
  • Thank you received: 66
Hello,

You can try to comment this line :

parent_array = ;

And call the function at the end of the script :
dynamic1(document.getElementById('first dropdown name'),'second dropdown name');

Also make sure to remove the pipe from the first dropdown items property.
Please note: my help is not official customer support. To receive your support, submit a ticket by clicking here
Regards,
RSJoomla! Development Team
Last Edit: 15 years 4 months ago by octavian.
The administrator has disabled public write access.

Re:Need default values for Dynamic Drop-down change 15 years 4 months ago #9454

How would I go about having the default value disallowed?
I would like to have the form submission fail if the default value is selected.

donmarvin wrote:
<script type="text/javascript">
function dynamic1(parent,child)
{
	var parent_array = new Array();
	// This is the default value
	//parent_array[''] = ['Corporate'];
	parent_array[''] = ['Select Division'];
	// All other elements
	// parent_array['PARENT NAME'] = ['CHILD 1','CHILD 2','CHILD 3','ETC'];
	parent_array['Corporate'] = ['John Doe','Mary Smith'];
	parent_array['Sales'] = ['Jane Doe','John Smith'];
	parent_array['Research'] = ['Bugs Bunny','Minnie Mouse'];
 
	// 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.

Re:Need default values for Dynamic Drop-down change 15 years 1 month ago #10250

I have the same question - in fact, I'd like to do exactly what Qausi is doing. Any help?
The administrator has disabled public write access.

Need default values for Dynamic Drop-down change 11 years 10 months ago #23917

  • yagachi
  • yagachi's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
Hi
I am really a beginner and I need to do a dynamic drop down as well bu I don't know why when I am using this script on RSform Pro it doesn't work on Joomla.
function dynamic1(parent,child){
 
	var parent_array = new Array();
 
	parent_array['Host Family'] = ['Please choose one option','Homestay single room breakfast standard zones 3,4','Homestay single room breakfast superior zones 2,3,4','Homestay single room half board standard zones 3,4','Homestay single room half board zones 2,3,4','Homestay single room breakfast executive zones 1,2','Homestay single room halfboard executive zones 1,2];
 
	parent_array['House Share'] = ['Please choose one option','House share single room zone 2','House share twin room zone 2'];
 
	parent_array['Residence'] = ['Please choose one option','Residence single room standard zone 3','Residence single room superior zone 2'];
 
	parent_array['Hostel'] = ['Please choose one option','Hostel accommodation zone 3'];
 
 
	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];} }

Thank you for your reply
Last Edit: 11 years 10 months ago by octavian.
The administrator has disabled public write access.

Need default values for Dynamic Drop-down change 11 years 10 months ago #23918

  • octavian
  • octavian's Avatar
  • NOW ONLINE
  • RSJoomla! Official Staff
  • Posts: 783
  • Thank you received: 110
Hello,

You have an error here:
'Homestay single room halfboard executive zones 1,2];

There's no ending apostrophe. Please add it:
'Homestay single room halfboard executive zones 1,2'];
Please note: my help is not official customer support. To receive your support, submit a ticket by clicking here
Regards,
RSJoomla! Development Team
The administrator has disabled public write access.
The following user(s) said Thank You: yagachi

Need default values for Dynamic Drop-down change 11 years 10 months ago #23919

  • yagachi
  • yagachi's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
Thanks one question before writting the script in /scripts, do I have to create 2 drop down (one with the parents details, the second with the child details),
I am really sorry if those questions are stupid but I try to learn how it works tank you.
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!