Jquery getting the value of a parent element input when checking a child checkbox

badvnn

New Member
I have this set of forms, when the user checks the input, I need to get the value that is outside this div, basically a parent div, try it to do it using .parent() and then find but could not make it work, not sure what do I am doing wrong, I have a js http://jsfiddle.net/creativestudio/bCgeD/2/This is my js:\[code\] function set_index_id_checkbox() { $("input:checkbox[name='like']").each(function(index){ var currElem = $(this); var prevLabel = currElem.next(); currElem.attr("id", this.id + index); prevLabel.attr("for", prevLabel.attr("for") + index); }); } set_index_id_checkbox(); function getValues(){ $("input:checkbox[name='like']").click(function(){ if (this.checked) { $(this).closest('.reply-form').find('.feedback_nid').text(this.value); } else { // ... } }); } getValues();\[/code\]and this is my html: \[code\] <input type="hidden" class="feedback_nid" value="http://stackoverflow.com/questions/13871673/form a 111"> <input type="hidden" class="branch_nid" value="http://stackoverflow.com/questions/13871673/form a 222"> <div class="block"> <!-- value --> <span class="info-item float-left value"> <span class="likes">value</span> </span><!-- /.value --> <!-- checkbox --> <div class="btn like-checkbox float-right"> <input id="like" class="like" type="checkbox" name="like" value="http://stackoverflow.com/questions/13871673/33"> <label class="like" for="like">like 1</label> </div><!-- /checkbox --> </div> </div> <div class="reply-form"> <input type="hidden" class="feedback_nid" value="http://stackoverflow.com/questions/13871673/form a 111"> <input type="hidden" class="branch_nid" value="http://stackoverflow.com/questions/13871673/form a 222"> <div class="block"> <!-- value --> <span class="info-item float-left value"> <span class="likes">value</span> </span><!-- /.value --> <!-- checkbox --> <div class="btn like-checkbox float-right"> <input id="like" class="like" type="checkbox" name="like" value="http://stackoverflow.com/questions/13871673/45"> <label class="like" for="like">like 2</label> </div><!-- /checkbox --> </div> </div> <div class="reply-form"> <input type="hidden" class="feedback_nid" value="http://stackoverflow.com/questions/13871673/form a 111"> <input type="hidden" class="branch_nid" value="http://stackoverflow.com/questions/13871673/form a 222"> <div class="block"> <!-- value --> <span class="info-item float-left value"> <span class="likes">value</span> </span><!-- /.value --> <!-- checkbox --> <div class="btn like-checkbox float-right"> <input id="like" class="like" type="checkbox" name="like" value="http://stackoverflow.com/questions/13871673/66"> <label class="like" for="like">like 3</label> </div><!-- /checkbox --> </div> </div>?\[/code\]
 
Back
Top