Jump to content
  • 0

Cascading Dropdown Not Working


theconav
 Share

Question

Hello dear Caspio community.

 

I m facing the following problem and would appreciate any help.

 

I have a Virtual Field set as a dropdown list and another virtual field referencing the first one as a cascading dropdown list. 

 

When manually changing the value of the first dropdown list, the cascading dropdown list on the other virtual field works perfectly. However, when changing the value of the dropdown list dynamically (through some javascript code), the cascading dropdown does not change at all. Any ideas ?

 

The javascript code i m using is the following :

 

...

 

var vRegistryCode = vGSPCode + '-' + vLocation ;

document.getElementsByName('cbParamVirtual7')[0].value = vRegistryCode;
document.getElementsByName('cbParamVirtual7')[0].onchange();
 
...
 
P.S. cbParamVirtual7 is my first Dropdown list.
 
Thank you very much !
 
 
Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

When we have parent and cascading dropdowns, we are already using onchange function for the parent dropdown. To be able to reuse onchange for the parent we can use this script below:
 

var change = document.getElementsByName('PARENT DROPDOWN ID')[0].getAttribute('onchange');

document.getElementsByName('PARENT DROPDOWN ID')[0].setAttribute('onchange', change + 'ABC();');


The first line is saving the onchange attribute into a temporary variable. The second line adds the function ABC, which you want to execute on the parent change, to the onchange attribute of the cascading. So both will be executed.

For instance if we had parent State and Cascading City on a submission page and I want to get an alert when State changes I use this code:

 

<script>
var change = document.getElementsByName('InsertRecordState')[0].getAttribute('onchange');

document.getElementsByName('InsertRecordState')[0].setAttribute('onchange', change + 'hi();');

function hi(){
alert("Hello World!");
}
</script>
Link to comment
Share on other sites

  • 0

Hi MayMusic

 

Thank you very much for your prompt reply. 

 

I actually do not want to call any function. Sorry if my previous description was misleading. All I need is the cascading to work (!!)

 

Taking the State and City example you mention, my problem is that if i manually change the value of the State (by clicking the dropdown list and selecting a different state from the the available entries) then the cascading city works perfectly. 

 

The problem arrises when, through the javascript code, I force a specific state as the value of the state dropdown

i.e.  getElementsByName(InsertRecordState')[0]=vSomeState rather than manually opening the dropdown list and selecting some state from there. In that case the cascading city does not work (i.e the value of the cascading city does not change).

 

Would appreciate your help in this

 

Many thanks !

Link to comment
Share on other sites

  • 0

Hello theconav,

 

If I understand correctly, you can try the following code:

document.getElementsByName('cbParamVirtual7')[0].selectedIndex = 0;
document.getElementsByName('cbParamVirtual7')[0].click;

By SelectedIndex your define number of the option that will be selected. It starts from 0.

When you "click" the dropdown, the child dropdown can change values.

 

I hope, it helps.

Link to comment
Share on other sites

  • 0

Hi Jan and thank you very much for your reply.

 

I tried it but unfortunately it does not work. 

 

Well, I assume that the first line can be replaced by document.getElementsByName('cbParamVirtual7')[0].value = 'XXX';

 

I tried it with both options (both by selecting the index of the item as you stated as well as by entering the value as above). This works and the value changes, however "click" does not seem to work.

 

Any other suggestions?

 

Again, thanks for your time

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...