Link to home
Create AccountLog in
Avatar of VBdotnet2005
VBdotnet2005Flag for United States of America

asked on

Bootstrap - clear input

I am trying to use Bootstrap 3 and wanting to add clear on each textbox. It is not working. How should I fix it?

Javascript
    
            $(document).ready(function(){
                $(".TextBox").keyup(function(){
                    $(this).siblings(".searchclear").toggle(Boolean($(this).val()));
                });
                $(".searchclear").toggle(Boolean($(".TextBox").val()));
                $(".searchclear").click(function(){
                    $(".searchinput").val('').focus();
                    $(this).hide();
                });
            });
            
            
            
CSS
            
             .searchinput {
    width: 200px;
}

.searchclear {
    position:absolute;
    right:5px;
    top:0;
    bottom:0;
    height:14px;
    margin:auto;
    font-size:14px;
    cursor:pointer;
    color:#ccc;
}



HTML

<div class="btn-group">
 
   <asp:TextBox ID="UserID" runat="server" class="form-control" placeholder="UserID" autofocus></asp:TextBox>
  <span id="searchclear" class="searchclear glyphicon glyphicon-remove-circle"></span>
</div>

<div class="btn-group">

   <asp:TextBox ID="Password" runat="server" TextMode="Password" class="form-control" placeholder="Password"></asp:TextBox>
  <span id="searchclear" class="searchclear glyphicon glyphicon-remove-circle"></span>
</div>

Open in new window

Avatar of sajayj2009
sajayj2009

what is ".searchinput"?
Avatar of VBdotnet2005

ASKER

Actually, they should be UserID and Password id from textbox.

JS
    
            $(document).ready(function(){
                $(".TextBox").keyup(function(){
                    $(this).siblings(".searchclear").toggle(Boolean($(this).val()));
                });
                $(".searchclear").toggle(Boolean($(".TextBox").val()));
                $(".searchclear").click(function(){
                    $(".searchinput").val('').focus();
                    $(this).hide();
                });
            });
            
            
            
CSS
            
             .searchinput {
    width: 200px;
}

Open in new window

 $(document).ready(function(){
                $(".TextBox").keyup(function(){
                    $(this).siblings(".searchclear").toggle(Boolean($(this).val()));
                });
                $(".searchclear").toggle(Boolean($(".TextBox").val()));
                $(".searchclear").click(function(){
                    $(".UserID").val('').focus();
                    $(this).hide();
                });
            });
            
            
            
CSS
            
             .UserID{
    width: 200px;
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of sajayj2009
sajayj2009

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer