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 tried .val('')
and .val(null)
, but neither worked for me.
Here is the full code:
$("#hdselect").click(function(){ $(".modal").html(""); $.post('mediaservice.php',{hd:'ok',images:$("#hdimages").val()},function(data){ $(".modal").append(data); }); $(".modal").dialog({ 'modal':true, 'title':"Click the image to select", 'width':960, 'height':600, 'resizable':false, 'show': {effect: 'drop', direction: "up"}, 'buttons': {"Ok": function() { var hd=Array(); var hdval=$("#hdimages").val(); $("#hdimages").attr('value',' '); $("input[name='hd[]']:checked").each(function(){ hd.push($(this).val()); }); if(hdval!=''){ hdval=hdval+","+hd; }else{ hdval=hd; } $("#hdimages").val(hdval); var images=$("#hdimages").val(); $.post('mediaservice.php',{getHd:images},function(data){ $("#imgthumbBase").append(data); }); $(this).dialog("close"); } } }); });
The idea is that the user clicks a button and a modal dialog opens with multiple images and checkboxes. At this point I need to get the values from an input, and then clear it.
jQuery isEmptyObject() method The isEmptyObject() method is used to determine whether the passed argument is an empty object or not. It returns a Boolean value. If it finds the passed value is an empty object, it returns true. Otherwise, it returns false.
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.
You could try:
$('input.class').removeAttr('value'); $('#inputID').removeAttr('value');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With