How to hide a textbox based on a selected dropdown value

Modified on Mon, May 27, 2019 at 12:14 PM

Add the following to the dropdown block:

Command: attribute

Value: onchange="hideBlock(this,'Name')";

Where ‘Name’ is the block name to hide

Add the following JS code to the Main Template

<script>
function hideBlock(obj,bname)
{
var col = $(obj).val();
var b = $("input[data-blockname='" + bname + "']");
if (col=="Blue") {
// Hide
b.val("");
b.parent().hide();
b.parent().siblings().hide();
}
else
{
// Show
b.parent().show();
b.parent().siblings().show();
        }  

    }

    // Runs when Page Loads
function _initLoad()
{
hideBlock($("select[data-blockname=Colour]"),"Name");
}
</script>


Where ‘Blue’ is the value when selected, block ‘Name’ will hide. The extra lines are there to hide the label as well.

Colour is the name of the Block to hide.


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article