I have a dynamic select form made with script.
When submiting with an error I want the form to stay open and save the data, but the form only opens when change is detected.
Ideally I would have the form open with "default value" but change it with listening.
$('#productType').change(function() {
if($(this).val() == 'dvd') {
$('#nextStep').html('<label for="size">Size (MB) </label><input type="text" id="size" name="size" value="<?php if (!empty($_POST["size"])) { echo $_POST["size"]; } else { echo ''; }; ?>" required>');
}
if($(this).val() == 'book') {
$('#nextStep').html('<label for="weight">Weight (KG) </label><input type="text" id="weight" name="weight" value="<?php if (!empty($_POST["weight"])) { echo $_POST["weight"]; } else { echo ''; }; ?>" required>');
}
if($(this).val() == 'furniture'){
$('#nextStep').html('<label for="height">Height (CM) </label><input type="text" id="height" name="height" value="<?php if (!empty($_POST["height"])) { echo $_POST["height"]; } else { echo ''; }; ?>" required><br><br><label for="width">Width (CM) </label><input type="text" id="width" name="width" value="<?php if (!empty($_POST["width"])) { echo $_POST["width"]; } else { echo ''; }; ?>" required><br><br><label for="lenght">Lenght (CM) </label><input type="text" id="lenght" name="lenght" value="<?php if (!empty($_POST["lenght"])) { echo $_POST["lenght"]; } else { echo ''; }; ?>" required>');
}
});