Reputation: 40
I have an input which has default value. In some cases default value would be nothing (I mean input would be empty) So the code will be something like this:
<input type="text" class="srlz" value="" />
then i have a jquery function which should serialize non empty inputs. (and the selects which their values are not -1) by this code:
$(":input.srlz[value!='']").not(":has(option[value='-1']:selected)").serialize();
or:
$(":input.srlz").not(":has(option[value='-1']:selected)").not("[value='']").serialize();
but the code does not serialize mentioned input although i enter value for the input, since it has default value ( value=""
).
I've just tested the following input instead of the first line and it works good.
<input type="text" class="srlz" />
how can i fix the problem?
Upvotes: 0
Views: 74
Reputation: 1634
Input value attribute is not the same as input value property. Attributes are set in DOM and can contain only string. Properties are a part of object, they can store other types like bool.
When you use :input[value!='']
you check the attribute, but when you edit the input then js set their property (that is why you don't see the actual value in DOM inspector in developer tools).
The solution is to create the filter() that check the value property.
$(...).filter( function() {
return $(this).val() !== '';
})...
http://jsfiddle.net/mpuc52dk/2/
Upvotes: 1