JSFiddle - React, Tailwind, and code Playground
HTML
<template>
<form method="post">
<input type="text" name="random" value="123">
<input type="submit">
</form>
</template>
<button>
showForm();
</button>
JavaScript
var form = $('form');
function handleFormSubmit() {
form.off('submit');
form.submit(function(e) {
e.preventDefault();
$('body').append($('<p />').text("Random: " + $('input[name="random"]', form).val()));
});
}
$('button').click(function() {
if (form.length == 0) {
var template = $("template").html();
$('body').append(template);
form = $('form');
} else {
$('input[name="random"]', form).val(Math.random());
}
handleFormSubmit();
});
for (var i = 0; i < 5; i++) {
$('button').click();
}
form.submit();