I am trying to add text into a hidden text box in the div below when a use clicks delete…
Html
<div class="documentRow">
<div class="documentHeader">
<b>Title:</b>
<input data-val="true" data-val-required="Required" id="EventDocuments_1__Title" name="EventDocuments[1].Title" style="width:100px" type="text" value="test.doc">
</div>
<div class="documentDelete">
<input data-val="true" data-val-required="The Delete field is required." id="EventDocuments_1__Delete" name="EventDocuments[1].Delete" type="hidden" value="False">
</div>
<div class="deleteDoc">
<button class="button delDocButton ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false"><span class="ui-button-text">Delete</span></button>
</div>
Jquery:
$(".delDocButton").click(function() {
$(this).parent().parent().toggle();
$(this).parent().find(".documentDelete input").val("True");
return false;
});
i have several of these “rows” on the page, so i cant reference the text box by id.
the problem is this line:
$(this).parent()is the direct parent of the button (<div class="deleteDoc">), and your hidden field is not in there so it wontfindit.To save having to repeat the calls to
parent()I suggest sometihng likethis:Live example: http://jsfiddle.net/SqHzU/