
Untitled
By: a guest on
Jun 9th, 2012 | syntax:
None | size: 1.17 KB | hits: 16 | expires: Never
iterate through textboxes
foreach(i = 0, i<20, i++)
{
<input type = "Text" id="q_i">
}
$('input[type=text]').each(function(){if ($(this).val() == '') alert("Your Message Here");});
$('[id^="q_"]').each(function(){if ($(this).val() == '') alert("Your Message Here");});
foreach(i = 0, i<20, i++)
{
if (document.getElementById('q_' + i).length == 0) {
alert('box ' + i + 'is empty!');
}
}
document.getElementsById('q_'+i)[0].value.length > 0
foreach(i = 0, i<20, i++)
{
<input type = "Text" id="q_i" class="q">
}
$("q").each(function(index,object){
if(object.value().length <= 0) alert('empty!');
});
$(document).ready(function() {
$("button").click(function()
{ $('span[id^=q_]').addClass("hidden");
$('input[id^=q_]').each(function()
{if ($(this).val().replace(/ /g,'') == '')
{ $("#"+$(this).attr('id')).removeClass("hidden");
}
});
});
});
<style>.hidden{display:none;}
.visible{display:block;}
</style>
<span id="q_1" class="hidden">Missing text</span>
<input type = "Text" id="q_1">