Reputation: 107
i am rather new to jquery and i am trying to do the below code
var entityType = $('.unit-edit-entity_type input', self.$rowInEdit).val();
var parentType = $('.unit-edit-parent_id select', self.$rowInEdit).val();
$('.unit-edit-entity_type', self.$editEmptyForm).val(entityType);
$('.unit-edit-parent_id', self.$editEmptyForm).val(parentType);
the var
is getting the right value but after creating the jquery value using the class and set the value from the var the result is ''
I cant figure out why. Thank to all.
Upvotes: 0
Views: 72
Reputation: 2449
I think that if self.$editEmptyForm is an element you should be doing;
$('.unit-edit-entity_type, ' + self.$editEmptyForm).val(entityType);
$('.unit-edit-parent_id, ' + self.$editEmptyForm).val(parentType);
Upvotes: 0
Reputation: 1142
$('unit-edit-entity_type', self.$editEmptyForm).val(entityType);
$('unit-edit-parent_id', self.$editEmptyForm).val(parentType);
Should be
$('.unit-edit-entity_type', self.$editEmptyForm).val(entityType);
$('.unit-edit-parent_id', self.$editEmptyForm).val(parentType);
You forgot a .
Upvotes: 3
Reputation: 22619
Prefix .
for Class Selector (“.class”)
Change
$('unit-edit-entity_type', self.$editEmptyForm).val(entityType);
$('unit-edit-parent_id', self.$editEmptyForm).al(parentType);
To
$('.unit-edit-entity_type', self.$editEmptyForm).val(entityType);
$('.unit-edit-parent_id', self.$editEmptyForm).val(parentType);
Upvotes: 1