I’m trying to make a modal dialog with images where you can select multiple images. I need to get values from an input and then to empty it, but I cannot empty the input. I
A better way is:
$("#element").val(null);
You could try:
$('input.class').removeAttr('value');
$('#inputID').removeAttr('value');
$('.reset').on('click',function(){
$('#upload input, #upload select').each(
function(index){
var input = $(this);
if(input.attr('type')=='text'){
document.getElementById(input.attr('id')).value = null;
}else if(input.attr('type')=='checkbox'){
document.getElementById(input.attr('id')).checked = false;
}else if(input.attr('type')=='radio'){
document.getElementById(input.attr('id')).checked = false;
}else{
document.getElementById(input.attr('id')).value = '';
//alert('Type: ' + input.attr('type') + ' -Name: ' + input.attr('name') + ' -Value: ' + input.val());
}
}
);
});
Usual way to empty textbox using jquery is:
$('#txtInput').val('');
If above code is not working than please check that you are able to get the input element.
console.log($('#txtInput')); // should return element in the console.
If still facing the same problem, please post your code.
To make values empty you can do the following:
$("#element").val('');
To get the selected value you can do:
var value = $("#element").val();
Where #element
is the id of the element you wish to select.
Another way is:
$('#element').attr('value', '');