I am trying to create a submit form that shows after clicking on a div and then retreive the filled in form data. Below is a test that I'm playing with for a day now. The variable "term" is always printed as undefined. Could anybody help me with this?
$(document).ready(function () {
$("#nexttable").on("click", "#addcomment", function () {
document.getElementById("nexttable").innerHTML = "<form action='maindatabase.php' id='commentform' method='post'><textarea name='newcomment' placeholder='Start typing your comment... (required)' rows='5' cols='50' required></textarea><br />"
+ "<span id='sbutton'><input type='button' value='Submit'></span><input type='hidden' name='inputtype' value='3'></form>";
});
});
$(document).ready(function () {
$("#nexttable").on("click", "#sbutton", function () {
var $form = $(this);
var term = $form.find("input[name='newcomment']").val();
document.getElementById("nexttable").innerHTML = term;
});
});