By clicking on DIV clear textbox

Asked

Viewed 79 times

0

I have some DIV that open a modal, but I would like that when clicked, clear the textbox, here is where I have the DIV that when clicking opens the modal:

 <div class="link-box">
                <a href="#dialog" name="modal" class="linkmodal" runat="server" id="modalExercutar">Cadastro de agenda avaliação física</a>
            </div>

I tried to do a function in JS but it did not work.

I also wanted to clear only the selection of gridview. Ex: I click to select a line, when clicking on the linkmodal, leave no lines selected.

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" DataKeyNames="id" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" PageIndex="10" SelectedIndexChanged="GridView1_SelectedIndexChanged" TabIndex="10" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDataBound="GridView1_RowDataBound" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing" OnSelectedIndexChanged="GridView1_SelectedIndexChanged1" PageSize="1000000">
                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                    <Columns>
                        <asp:BoundField DataField="id" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="id" />
                        <asp:BoundField DataField="data" HeaderText="Data" SortExpression="data" DataFormatString="{0:d}" HtmlEncode="False" />
                        <asp:BoundField DataField="hora" HeaderText="Hora" SortExpression="hora" HtmlEncode="False" />
                        <asp:BoundField DataField="avaliador" HeaderText="Avaliador" SortExpression="avaliador" HtmlEncode="False" />
                        <asp:BoundField DataField="Aluno" HeaderText="Aluno" SortExpression="Aluno" HtmlEncode="False" />
                        <asp:BoundField DataField="razao_social" HeaderText="Empresa" SortExpression="razao-social" HtmlEncode="False" />
                        <asp:ButtonField CommandName="Select" Text="<img src='images/icon/Misc-Edit-icon.png' title='Editar'/>" />
                        <asp:CommandField ShowDeleteButton="True" DeleteText="<img src='images/icon/Trash-can-icon.png' title='Excluir' />" />
                    </Columns>
                    <EditRowStyle BackColor="#999999" />
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                    <SortedAscendingCellStyle BackColor="#E9E7E2" />
                    <SortedAscendingHeaderStyle BackColor="#506C8C" />
                    <SortedDescendingCellStyle BackColor="#FFFDF8" />
                    <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                </asp:GridView>

1 answer

1


With JS it would look like this:

jQuery(function($){
   $('.linkmodal').click(function(){
        $('#txtid').val('');          
   });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="link-box">
       <a href="#dialog" name="modal" class="linkmodal" runat="server" id="modalExercutar">Cadastro de agenda avaliação física</a>
</div>
<br><br>

Textbox <input type="text" id="txtid" value="teste">

With respect to grid try the following script:

jQuery(function($){
   $('.linkmodal').click(function(){
        $("#GridView1").empty();          
   });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="link-box">
    <a href="#dialog" name="modal" class="linkmodal" runat="server" id="modalExercutar">Cadastro de agenda avaliação física</a>
</div>

<br><br>

<div id="GridView1" style="border:1px solid; height: 40px;">
conteúdo
</div>

I did it with a div using the same id as the grid to illustrate, since here it is not possible to test the code of grid, note that by clicking the div remains, but the content is deleted.

  • I did it this way that informed Leandro, but it doesn’t work. I just changed the textbox by txtid that is the ID in my textbox.

  • @marianac_costa Try again, I edited the post putting exactly the informed id. Remembering that you have to put the script call (jquery.min.js) inside the page’s head tag.

  • 1

    It worked right Leandro, thanks. You know how I do to clear grid selection in function? Wanted along with this. Thanks.

  • @marianac_costa Edit the main post and post the code snippet of the grid so I can see how the grid in question is doing and edit the answer with the function to clear the grid as well.

  • I edited .. the way I’m doing, it disappears the grid, I’d like you to just clear the selection. Thanks.

  • @marianac_costa I edited the post by placing a script to clean the content without removing the grid, I did it with a div to illustrate the behavior of the script.

  • This way he is removing the Grid.

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.