Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 9th, 2012  |  syntax: None  |  size: 1.17 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. iterate through textboxes
  2. foreach(i = 0, i<20, i++)
  3. {
  4. <input type = "Text" id="q_i">
  5. }
  6.        
  7. $('input[type=text]').each(function(){if ($(this).val() == '') alert("Your Message Here");});
  8.        
  9. $('[id^="q_"]').each(function(){if ($(this).val() == '') alert("Your Message Here");});
  10.        
  11. foreach(i = 0, i<20, i++)
  12. {
  13.   if (document.getElementById('q_' + i).length == 0) {
  14.     alert('box ' + i + 'is empty!');
  15.   }
  16. }
  17.        
  18. document.getElementsById('q_'+i)[0].value.length > 0
  19.        
  20. foreach(i = 0, i<20, i++)
  21. {
  22. <input type = "Text" id="q_i" class="q">
  23. }
  24.        
  25. $("q").each(function(index,object){
  26.   if(object.value().length <= 0) alert('empty!');
  27. });
  28.        
  29. $(document).ready(function() {
  30.                 $("button").click(function()
  31.                 {   $('span[id^=q_]').addClass("hidden");
  32.                     $('input[id^=q_]').each(function()
  33.                     {if ($(this).val().replace(/ /g,'') == '')
  34.                         {   $("#"+$(this).attr('id')).removeClass("hidden");
  35.                         }
  36.                 });
  37.                 });
  38.  });
  39.        
  40. <style>.hidden{display:none;}
  41.        .visible{display:block;}
  42. </style>
  43. <span id="q_1" class="hidden">Missing text</span>
  44. <input type = "Text" id="q_1">