inside a jquery method (on a click event of a button) i have the following code:
$(selector).html("<form action='/Tracker/CopyFood' method='post'><input type='hidden' name='Id' value=" + id + "><input class='very-small-input' type='text' name='Quantity' value='1' /> for <select name='Date'><option value='Today'>Today</option><option value='Yesterday'>Yesterday</option></select><select name='Meal'><option value='Breakfast'>Breakfast</option><option value='Lunch'>Lunch</option><option value='Dinner'>Dinner</option><option value='Evening Snack'>Evening Snack</option></select><input type='button' class='submitCopyFood' value='Add'> or <div style='display:inline' class='CancelCopy'>Cancel</div></form> ");
it seems to work on the screen, but the button click "submitCopyFood" the event was firing but it wasn't submitting the form. When i click "View Selection Source" in firefox, i see the issue. All i see is this:
<input name="Id" value="128" type="hidden"><input class="very-small-input" name="Quantity" value="1" type="text"> for <select name="Date"><option value="Today">Today</option><option value="Yesterday">Yesterday</option></select><select name="Meal"><option value="Breakfast">Breakfast</option><option value="Lunch">Lunch</option><option value="Dinner">Dinner</option><option value="Evening Snack">Evening Snack</option></select><input class="submitCopyFood" value="Add" type="button"> or <div style="display: inline;" class="CancelCopy">Cancel</div>
Its like i never added the form anywhere. Is there any reason why i dont see the:
<form action='/Tracker/CopyFood' method='post'>
or the
</form>
in the source code inside the selected source. Is there something special that i need to do here?
Updated:
here is the button click event. To be clear, this event fires fine but this line fails below:
var myForm = parentDiv.children('form');
because myForm is empty (as there is no form element)
Here is the full click event:
$(document).ready(function() {
$('.submitCopyFood').live('click', function() {
debugger;
var parentDiv = $(this).parent('.copyFoodInstance');
var myForm = parentDiv.children('form');
$.post(myForm.attr('action'), myForm.serialize(), function(data) {
debugger;
parentDiv.attr("fromInner", "1");
parentDiv.attr("myset", "0");
parentDiv.html("<img BORDER=0 src='../../images/copy1.png' />");
});
});
});