---
title: "Dropdown list textbox required field validator generate error"  
description: "Dropdown list textbox required field validator generate error"  
author: "Royce Roy"  
published: 2014-10-27  
updated: 2014-10-27  
canonical: https://www.mindstick.com/forum/2441/dropdown-list-textbox-required-field-validator-generate-error  
category: "asp.net"  
tags: ["asp.net", "validation"]  
reading_time: 2 minutes  

---

# Dropdown list textbox required field validator generate error

I have a [dropdown list](https://www.mindstick.com/forum/760/dropdown-list-open-hide-behind-another-dropdown-list-on-ie-7) for the which [values](https://www.mindstick.com/forum/327/sum-textbox-values) are coming from DB. There is one [option](https://www.mindstick.com/forum/159391/jquery-get-selected-option-from-dropdown) name OTHER, when I [select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) other the [textbox](https://www.mindstick.com/forum/12714/dynamic-textbox-in-gridview) appears. For that Textbox I have made a [required](https://www.mindstick.com/forum/160269/what-is-required-data-annotation-how-does-it-affect-model-validation) field [validator](https://www.mindstick.com/forum/156905/what-is-data-annotation-validator-attribute-in-asp-dot-net-mvc). Till here it [works fine](https://answers.mindstick.com/qa/115732/my-software-works-fine-on-windows-10-but-crashes-on-windows-11-why). But when I select any other option, still it gives me validator errors. It should not happen. It should only give me required field [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing) when the user doesn't fills the textbox on select of OTHER option. Please see the code.

## Dropdown and Textbox code:-

```
<asp:DropDownList ID="ddlGraduation" runat="server" CssClass="txtfld-popup_drp"></asp:DropDownList> <asp:RequiredFieldValidator CssClass="error_msg" ID="reqGraduation" runat="server" ControlToValidate="ddlGraduation" ErrorMessage="Please select graduation details" InitialValue="--Select--" SetFocusOnError="true"></asp:RequiredFieldValidator><asp:TextBox ID="txtOther" runat="server" CssClass="txtfld-popup_p"></asp:TextBox>                                                                                <asp:RequiredFieldValidator ID="reqOther" runat="server" ControlToValidate="txtOther" ErrorMessage="Please specify your qualification"></asp:RequiredFieldValidator>
```

JS code for hiding and show the textbox when user select and deselect the OTHER option from dropdown list:-

```
<script type="text/javascript">    function pageLoad() {        $('#ctl00_ContentPlaceHolder1_txtOther').hide();        $('#ctl00_ContentPlaceHolder1_ddlGraduation').change(function () {            if ($(this).val() === "Other") {                $('#ctl00_ContentPlaceHolder1_txtOther').show();            } else {                $('#ctl00_ContentPlaceHolder1_txtOther').hide();            }        });    };</script>
```

## Replies

### Reply by Samuel Fernandes

You need to enable your required field validator only when your textbox is visible, you need to write below line of code in your javascriot function when you are showing your textbox:\
ValidatorEnable(document.getElementById("reqGraduation"), true);\
\
**Your javascript code shuld be like this:**\

```
<script type="text/javascript">    function pageLoad() {        $('#ctl00_ContentPlaceHolder1_txtOther').hide();        $('#ctl00_ContentPlaceHolder1_ddlGraduation').change(function () {            if ($(this).val() === "Other") {                $('#ctl00_ContentPlaceHolder1_txtOther').show();                 ValidatorEnable(document.getElementById("reqGraduation"), true);            } else {                $('#ctl00_ContentPlaceHolder1_txtOther').hide();                 ValidatorEnable(document.getElementById("reqGraduation"), false);            }        });    };</script>
```


---

Original Source: https://www.mindstick.com/forum/2441/dropdown-list-textbox-required-field-validator-generate-error

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
