Possible Duplicate:
Check if inputs are empty using jQuery
I have form and textboxes, how will I determine if any of these textboxes is empty using javascript if else statement once a form button is clicked.
function checking() {
var textBox = $('input:text').value;
if (textBox == "") {
$("#error").show('slow');
}
}
Thanks in advance!
By using jQuery selectors for selecting the elements, you have a jQuery object and you should use
val()method for getting/setting value of input elements.Also note that
:textselector is deprecated and it would be better to trim the text for removing whitespace characters. you can use$.trimutility function.If you want to use
valueproperty you should first convert the jQuery object to a raw DOM object. You can use[index]orgetmethod.If you have multiple inputs you should loop through them.