I have 2 separate forms that displays in one iframe, I want users to enter data in the input, click on next button then enter input of form 2, click on a review button, then show form 1 and form 2 output in one preview page before submitting the data to a database. I have tried session storage but I know that my code is wrong.
Problem is that form 1 input doesnt show on the preview, only form 2 input shows.
var formValues = [];
SessionStorage.setItem("fname", "fname");
SessionStorage.setItem("lname", "lname");
SessionStorage.setItem("phone-field", "phone-field");
SessionStorage.setItem("email-field", "email-field");
$(document).ready(function() {
$(".next").click(fuction() {
$("#fname").val("fname");
$("#lname").val("lname");
$("#phone-field").val("phone-field");
$("#email-field").val("email-field");
var formValues = sessionStorage.getItem("fname");
console.log(formValues);
$(document).ready(function() {
$('.next').click(function() {
var formValues = [];
// get values from inputs in first fieldset
$('.field1 :input').each(function() {
formValues.push($(this).val());
});
formValues.pop(); //remove the button from input values
console.log(formValues);
// set values in second fieldset
$('.field3 :input').each(function(index) {
if (formValues[index]) {
$(this).val(formValues[index]);
}
});
$('.current').removeClass('current').hide().next().show().addClass('current');
});
$('.previous').click(function() {
$('.current').removeClass('current').hide().prev().show().addClass('current');
});
});
$(document).ready(function() {
$('.review').click(function() {
var formValues = [];
// get values from inputs in first fieldset
$('.field2 :input').each(function() {
formValues.push($(this).val());
});
formValues.pop(); //remove the button from input values
console.log(formValues);
// set values in second fieldset
$('.field3 :input').each(function(index) {
if (formValues[index]) {
$(this).val(formValues[index]);
}
});
$('.current').removeClass('current').hide().next().show().addClass('current');
});
$('.previous').click(function() {
$('.current').removeClass('current').hide().prev().show().addClass('current');
});
});
FORM 1
<head>
<link data-require="bootstrap@4.0.5" data-semver="4.0.5" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" />
<script data-require="bootstrap@4.0.5" data-semver="4.0.5" src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/js/bootstrap.min.js"></script>
<script data-require="jquery@3.1.1" data-semver="3.1.1" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body>
<form id="helpdeskform" action="process.php" method="post">
<fieldset class="field1 current">
<h2>Form</h2>
<p>
<label class="form-label first-name" for="fname">First Name:</label>
<input name="fname" id="fname" placeholder="First Name" type="text" />
</p>
<p>
<label class="form-label last-name" for="lname">Last Name:</label>
<input name="lname" id="lname" placeholder="Last Name" type="text" />
</p>
<p>
<label class="form-label" for="phone-field">Phone:</label>
<input name="phone" id="phone-field" placeholder="Phone Number" type="text" />
</p>
<p>
<label class="form-label" for="email-field">E-mail:</label>
<input name="email" id="email-field" placeholder="E-mail" type="text" />
</p>
<hr />
<label for="review">
<input onclick="location.href='index3.html'" id="next" name="next" class="next action-button" value="Next" type="button" />
</label>
</fieldset>
<fieldset class="field3">
<p>First Name:
<input class="show_fname" readonly="readonly" type="text" />
</p>
<p>Last Name:
<input class="show_lname" readonly="readonly" type="text" />
</p>
<p>Type of Request:
<input class="show_type_of_request" readonly="readonly" type="text" />
</p>
<p>Short Description:
<input class="show_subject" readonly="readonly" type="text" />
</p>
<p>Additional Comments:
<input class="show_comments" readonly="readonly" type="text" />
</p>
<p style="float:left;">
<label for="previous">
<input name="previous" class="previous action-button" value="Previous" type="button" />
</label>
</p>
<p style="float:left; padding-left: 10px;">
<label for="Submit">
<input value="Submit" name="submit" class="action-button" type="submit" />
</label>
</p>
</fieldset>
</form>
</body>
</html>
FORM 2
<!DOCTYPE html>
<html>
<head>
<link data-require="bootstrap@4.0.5" data-semver="4.0.5" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" />
<script data-require="bootstrap@4.0.5" data-semver="4.0.5" src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/js/bootstrap.min.js"></script>
<script data-require="jquery@3.1.1" data-semver="3.1.1" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body>
<form id="helpdeskform" action="process.php" method="post">
<fieldset class="field2 current">
<h2>Form 2</h2>
<label for="classify">Type of Request:</label>
<select name="classify" id="classify">
<option value="">Please select an option..</option>
<option value="maintainence">Maintainence of Site</option>
<option value="troubleshoot">Troubleshoot/Error</option>
<option value="new">Create new content</option>
</select>
<p></p>
<p>
<label for="subject">Short Description: <span class="counter-field">
<span id="counter"></span> characters left.</span>
</label>
<input name="subject" id="subject" placeholder="Subject" type="text" />
</p>
<p>
<label for="desc">Additional Comments:</label>
<textarea style="font-family: Arial, Veranda, Sans serif" name="desc" id="desc" cols="30" rows="10" placeholder="Short Description"></textarea>
</p>
<p>
<label for="review">
<input name="review" onclick="showData();" class="review action-button" value="Review" type="button" />
</label>
</p>
</fieldset>
<fieldset class="field3">
<!-- @TODO PREVIEW ALL FORM INPUTS -->
<p>First Name:
<input class="show_fname" readonly="readonly" type="text" />
</p>
<p>Last Name:
<input class="show_lname" readonly="readonly" type="text" />
</p>
<p>Phone:
<input class="show_phone" readonly="readonly" type="text" />
</p>
<p>E-mail:
<input class="show_email" readonly="readonly" type="text" />
</p>
<p>Type of Request:
<input class="show_type_of_request" readonly="readonly" type="text" />
</p>
<p>Short Description:
<input class="show_subject" readonly="readonly" type="text" />
</p>
<p>Additional Comments:
<input class="show_comments" readonly="readonly" type="text" />
</p>
<p style="float:left;">
<label for="previous">
<input name="previous" class="previous action-button" value="Previous" type="button" />
</label>
</p>
<p style="float:left; padding-left: 10px;">
<label for="Submit">
<input value="Submit" name="submit" class="action-button" type="submit" />
</label>
</p>
</fieldset>
</form>
</body>
</html>