0

I want to check all the textbox of a div are empty or not in jQuery

<div id="compWord">
<input id="c" ondrop="dropabc(event)" class="box ui-droppable" type="textbox">
<input id="c" ondrop="dropabc(event)" class="box ui-droppable" type="textbox">
<input id="c" ondrop="dropabc(event)" class="box ui-droppable" type="textbox">
</div>

I want to check all the div either they are empty or either they are full i need the selector for both of them

Tayyab Vohra
  • 1,512
  • 3
  • 22
  • 49
  • full means what? Has a value? – epascarello Aug 16 '16 at 18:02
  • @epascarello I want to check all the div whether they have value or not? – Tayyab Vohra Aug 16 '16 at 18:13
  • http://stackoverflow.com/questions/8907835/check-all-input-fields-have-been-filled-out-with-jquery – epascarello Aug 16 '16 at 18:14
  • 1
    first to mention that, using the same `id` for all fields is not a good coding practice.do you want to check this in a button click – caldera.sac Aug 16 '16 at 18:29
  • Note that: 1. You can not use the same `id="c"` for multiple inputs. 2. There is no `type="textbox"` do you mean `type="text"`? 3. You say "all the div are full" - what? Do you mean all the text inputs? 4. **Important**: You have to show your jQuery code for anyone to help. – random_user_name Aug 16 '16 at 20:53

2 Answers2

0
if ($('#element').is(':empty')){
  //do something
}

Use above code to check element is empty or not.

0

you can do it in so many ways, this is a very basic way of doing this as your request. try this small demo. note : please do not use same id for all elements.

<html>
<head></head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<body>

<div id="compWord">
 <input id="box0" class="box ui-droppable" type="textbox"> 
 <input id="box1" class="box ui-droppable" type="textbox">
 <input id="box2" class="box ui-droppable" type="textbox">
 <input type="button" id="checkyou" value="enter">
</div>
<h3 style="color:red;display:none;" id="warnme">You hava to fill all fields</h3>

</body>

<script type="text/javascript">
 
$("#checkyou").click(function(){
 for(i=0;i<3;i++)
  {
   var theId = "box"+i;
   var textval = $("#"+theId).val();
   alert(textval);// I put an alert to show you what is the value remove this if you do not want

   if (textval == "") 
   {
    $("#warnme").show();
   }
   else
   {
    $("#warnme").hide();
   }
   
  }
});
 

</script>

</html>

hope this will help to you.thank you very much.

caldera.sac
  • 4,918
  • 7
  • 37
  • 69