I have a simple python script and html code that I'm executing on my localhost. The code displays a simple form that allows the user to fill out their personal info and submit. Upon submission, a jquery script outputs whatever the user had submitted. This part of the code works. However, after outputting, the form immediately resets and the output disappears. How do I get everything to remain the same until the user manually changes a form field and re-submits?
Python script (app.py)
from flask import Flask, render_template
app = Flask(__name__)
@app.route("/")
def main():
return render_template('index.html')
if __name__ == "__main__":
app.run()
HTML code (index.html)
.container{
width: 500px;
clear: both;
margin-right: auto;
margin-left: auto;
}
.container input{
width: 100%;
clear: both;
}
html, body {
margin: 0;
height: 100%;
}
br {
margin:1.25em 0;/* Firefox */
line-height:2.5em;/* chrome */
}
</style>
<html>
<header>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</header>
<body>
<h1><center>Gettin' acquainted to docker</center></h1>
<div class="container">
<form>
Salutation<input type="text" id="salutation" required><br>
First Name<input type="text" id="firstname" required><br>
Last Name<input type="text" id="lastname" required><br>
<input type="submit" id="register" class= "get_greeting" value="Display" disabled="disabled" />
<div class="results"></div>
</form>
</div>
</body>
<script>
(function() {
$('form > input').keyup(function() {
var empty = false;
$('form > input').each(function() {
if ($(this).val() == '') {
empty = true;
}
});
if (empty) {
$('#register').attr('disabled', 'disabled');
} else {
$('#register').removeAttr('disabled');
}
});
})()
$(document).ready(function(){
$('.container').on('click', '.get_greeting', function(){
$('.results').html('<p>Hi, '+$('#salutation').val()+' '+$('#firstname').val()+' '+$('#lastname').val()+'. I am learning how to implement containers...</p>')
});
});
</script>
</html>