Im adding the form, in an on-click event, to a row in a table using (Sorry about the really long row):
$('#row'+rowvalues[0]).html('
<form id="updform'+rowvalues[0]+'">
<td>'+rowvalues[0]+'</td>
<td>
<input type="text" name="namn'+rowvalues[0]+'" value="'+rowvalues[1]+'">
</td>
<td>
<input type="text" name="ingred'+rowvalues[0]+'" value="'+rowvalues[2]+'">
</td>
<td>
<input type="number" name="pris'+rowvalues[0]+'" value="'+rowvalues[3]+'">
</td>
<td>
<input type="number" name="fampris'+rowvalues[0]+'" value="'+rowvalues[4]+'">
</td>
<td>
<Button class="upddatasave" id="sub'+rowvalues[0]+'">Submit</button>
</form>
</td>
');
intialiseUpdatebutton();
then I initialize the button using the fuction called intialiseUpdatebutton();
that function looks like:
function intialiseUpdatebutton() {
$(".upddatasave").on("click", function() {
var butid = $(this).attr('id');
var dataid = parseInt(butid.slice(3));
console.log(dataid);
console.log($('#namn'+dataid).val());
var formvalues = $('#updform'+dataid).serializeArray();
console.log(formvalues);
});
}
It finds the button and it works, but I can't find the form. My guess was that it cant find the injected form, but if that's the case how do I fix it? like I do with the initialise function for the button.
What Im trying to do: Im displaying data from an SQL table in a table in html - It has 2 buttons 1 update and 1 delete. Im trying to fix the update button so that when I press it the cells with the values change into a form with textfields and the values in there and then you can just change the values and press submit to save the changes.
Edit: jsfiddle.net/rh8deo79/2 <- jsfiddle