javascript - jQuery 'OR' not working when looping through required input elements -


i'm writing small required html5 attribute fallback various inputs. it's going pretty far, i'm having trouble when checking radio button ':checked' , using 'or' || operator in loop:

if (self.val() === '' || self.is(':not(:checked)')) { 

for reason when add breaks script , indicate input fields (type=text) empty when they're not. there better way @ loop through , indicate difference between input type 'text' , 'radio'?

here's loop:

var reqclass = $('.required')         reqclass.each(function(){              var self = $(this)              // if empty             if (self.val() === '' || self.is(':not(:checked)')) {                  // if doesn't have require-checked class                 if (!self.hasclass('require-checked')) {                      self.addclass('require-checked')                     self.parent().append('<span class="form-error">this field required.</span>')                  }                  e.preventdefault()                 //$('.form-submit').attr('disabled', true)              // if it's been checked, there value                } else if (self.hasclass('require-checked') && !(self.val() === '')) {                  self.siblings('.form-error').hide()              }          }) 

classes present 'fallback' browsers , changed on fly. here's jsfiddle, thank help:

http://jsfiddle.net/cyncv/2/

a text box indeed :not(:checked) (even if has text in it), text boxes showing empty when not.

perhaps like

if (self.val() === '' || self.is(':checkbox:not(:checked)') || self.is(':radio:not(:checked)') 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -