VBdotnet2005
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>
what is ".searchinput"?
ASKER
Actually, they should be UserID and Password id from textbox.
JS
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;
}
ASKER
$(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;
}
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.