how to make a textbox visible using javascript in modalpopup in asp.net

HOUSSEM MAHJOUBI 286 Reputation points
2023-02-22T14:46:42.17+00:00

Hi members

i have a textbox9 i want to make it visible if the textbox4="9999"

this is my code :

<script type="text/javascript">
    $(document).ready(function () {
       $("#<%=TextBox4.ClientID %>").autocomplete({
             
  $('TextBox9').attr('style', request.term == "9999" ? 'display:block;' : 'display:none;');    $('#Label20').attr('style', request.term == "9999" ? 'display:normal;' : 'display:none;');
 
           source: function (request, response) {
               
                
                
                   $.ajax({
                    type: "POST",
                    url: '<%=ResolveUrl("~/ArticleInvestigation.aspx/GetNames2") %>',
                    data: "{ 'prefix': '" + request.term + "'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
 
                       response($.map(data.d, function (item) {
                            return {
 
                                label: item.split('-')[0],
                                val: item.split('-')[1]
                            }
                        }))
                    },
                    error: function (response) {
                        alert(response.responseText);
                    }
                });
              
            },
             
            select: function (e, i) {
                
                $("[id$=hfName]").val(i.item.label);
                $.ajax({
                    type: "POST",
                    url: '<%=ResolveUrl("~/ArticleInvestigation.aspx/GetCountry2") %>',
                    data: "{ 'name': '" + i.item.label + "'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (response) {
                        $("[id*=TextBox3]").val(response.d.split('-')[0]);
                        $("[id*=TextBox6]").val(response.d.split('-')[1]);
                 
 
                    },
                    error: function (response) {
                        alert(response.responseText);
                    }
                });
               
           },
             
            minLength: 0
        });
    });
</script>

i want when the automplete get the click and the value equal to '9999' and the textbox4 receive that value after the

textbox9 should appear or disappear if not equal to '9999'

the is the textbox looks like and the label:

 
 <asp:TextBox ID="TextBox9" runat="server" Width="205px" style="display:none;"></asp:TextBox>
 <asp:Label ID="Label20" runat="server" Text="Client divers:" style="display:none;"></asp:Label> 

please help

Microsoft 365 and Office Development Office JavaScript API
Developer technologies VB
Developer technologies ASP.NET Other
{count} votes

Accepted answer
  1. Lan Huang-MSFT 30,186 Reputation points Microsoft External Staff
    2023-02-23T09:05:04.7866667+00:00

    Hi @HOUSSEM MAHJOUBI,

    You can put the code inside the select method.

     select: function (e, ui) {                                  
         $("#<%=TextBox9.ClientID %>").attr('style', ui.item.value == "9999" ? 'display:block;' : 'display:none;');
         $("#<%=Label20.ClientID %>").attr('style', ui.item.value == "9999" ? 'display:normal;' : 'display:none;');
                },
    
    

    TEST1

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.