简体   繁体   中英

if textbox has date entered into it, then display other textbox

I have a textbox where the user can select a date. When a date is selected, I want another textbox to be displayed. But the textbox is always displayed even if there is no date. If txtBookDate is empty then txtBookComment shouldn't display.

<tr id="trBookDate" runat="server" >
    <td>
        Book IN Date
     </td>
     <td>
        <asp:TextBox runat="server" ID="txtBookDate" rel="datepicker" ></asp:TextBox>
     </td>
 </tr>
 <tr id="trBookInComment" runat="server" >
       <td>
             Book IN Comment
        </td>
        <td>
            <textarea id="txtBookInComment" runat="server" width="100%" maxlength="40"></textarea>
        </td>
 </tr>



<script type="text/javascript">
           $('#<%= txtBookDate.ClientID %>').change(function () {
                if($(this) != null) {
                    $('#<%= trBookInComment.ClientID %>').show();   
                } else {
                    $('#<%= trBookInComment.ClientID %>').hide();   
                }
            });

 $('#<%= txtBookDate.ClientID %>').trigger('change');
 </script>

$(this) refers to the object, the first textbox itself, which is not null. It does not refer to the value in the textbox.

Try

if ($(this).val().length)...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM