Jump to content

Show/hide section using virtual field in cascading dropdown


Recommended Posts

I was able to show/hide a div based on the selection of a normal dropdown field using hints from this topic:

http://forums.caspio.com/index.php/topic/3466-using-parameters-to-dynamically-hide-sections/   It worked great, thanks.

However, now I want to do the same thing, except the "Yes/No" value in the field that controls the show/hide is a virtual field in a cascading dropdown. If the virtual field is "yes", I want the section to display. If "no", it should remain hidden. I have tried various versions of the code shown on this topic (above), but not sure how to make it work.

The cascading virtual field is "Virtual1" and the div to show/hide has ID "HideSharing".
I have this code in the footer:

<script type="text/javascript">
var dropdown2 = document.getElementsByName('cbParamVirtual1')[0];

dropdown2.onchange = function() {
var dropdown2 = document.getElementsByName('cbParamVirtual1')[0];

var hidableSection2 = document.getElementByID('HideSharing');
hidableSection2.style.display =
dropdown2.options[dropdown2.selectedIndex].value == 'Yes'
? 'inline'
: 'none';
}
</script>

Any help would be appreciated.

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...
Please try this and let me know if it works for you:

 



<script type="text/javascript">
var dropdown2 = document.getElementsByName('cbParamVirtual1')[0];
function f_hide() {
 var hidableSection2 = document.getElementById('HideSharing');
 hidableSection2.style.display = dropdown2.options[dropdown2.selectedIndex].value == 'Yes'?'inline':'none'; 

document.getElementsByName('cbParamVirtual1')[0].onchange = f_hide;
</script>

Link to comment
Share on other sites

I am using IE9. After your post, I tested in FireFox, Chrome, and Safari and had success with each of those. So, there is apparently something in the code that IE does not like. The user base for this will be using IE exclusively, so a fix is definitely needed. Thanks for looking at it! :)

Link to comment
Share on other sites

  • 6 years later...

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
Reply to this topic...

×   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...
×
×
  • Create New...