Using jQuery, how can I clear the input text after I made a click? By default, the value remains in the input field.
For example, I have an input text and the value is <
try this
$("input[name=search-mini]").on("search", function() {
//do something for search
});
enter code here<form id="form">
<input type="text"><input type="text"><input type="text">
<input type="button" id="new">
</form>
<form id="form1">
<input type="text"><input type="text"><input type="text">
<input type="button" id="new1">
</form>
<script type="text/javascript">
$(document).ready(function(e) {
$("#new").click( function(){
//alert("fegf");
$("#form input").val('');
});
$("#new1").click( function(){
//alert("fegf");
$("#form1 input").val('');
});
});
</script>
$('.mybtn').on('click',
function(){
$('#myinput').attr('value', '');
}
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class="mybtn">CLEAR</button>
<input type="text" id="myinput" name="myinput" value="ааааааааа">
Using jQuery ...
$('#submitButtonsId').click(
function(){
$(#myTextInput).val('');
});
Using pure Javascript ...
var btn = document.getElementById('submitButton');
btn.onclick = function(){ document.getElementById('myTextInput').value="" };
I am supposing you are trying to create a effect, where the textbox contains a label. And when the user click in the textbox, it disappears and lets the user input the text. You do not require Jquery for this.
<input type="text" value="Input Text" onfocus="this.value=''" onblur="(this.value=='')? this.value='Input Text':this.value;" />
Demo
I would recommend to use this since I have the same issue which got fixed.
$('input:text').focus(
function(){
$(this).val('');
});