I was wondering if there was a way to set the value of an input (returned via an ajax call) before appending it to the document.
$(function () {
$("#addItem").click(function () {
var numRows = $('.row').length;
$.ajax({
url: this.href,
cache: false,
success: function (html) {
// find input id in html that contains Order ?
// set value of the input to numRows + 1 ?
// append updated html to an element called #rows
$("#rows").append(html);
}
});
return false;
});
Thanks for any help
Here's what the html might look like
<div class="row">
<input type="hidden" name="OfficialAddresses.index" autocomplete="off" value="1cffe209-44e1-44ca-a013-a808bff8a174">
<fieldset>
<legend>Address</legend>
<div class="editor-field">
<input class="text-box single-line" id="OfficialOfficialAddresses_1cffe209-44e1-44ca-a013-a808bff8a174__Order" name="OfficialOfficialAddresses[1cffe209-44e1-44ca-a013-a808bff8a174].Order" type="text" value="0">
</div>
<div class="clear">&nsbp;</div>
<a href="#" class="deleteRow">delete</a>
<div class="clear">&nsbp;</div>
</fieldset>
</div>
Orderyou can use the jQueryattribute-ends-width-selector.$html.find('input[id$=Order]')