mirror of
https://github.com/FAUSheppy/jeffrey_miller_flask_ftp
synced 2025-12-06 07:51:34 +01:00
submit javascript
This commit is contained in:
58
static/submit.js
Normal file
58
static/submit.js
Normal file
@@ -0,0 +1,58 @@
|
||||
function submitForm(){
|
||||
|
||||
/* check input fields */
|
||||
nameField = document.getElementById("name")
|
||||
passwordField = document.getElementById("password")
|
||||
|
||||
nameField.style.borderColor = "gray"
|
||||
passwordField.style.borderColor = "gray"
|
||||
|
||||
invalidField = false
|
||||
if(nameField.value == ""){
|
||||
nameField.style.borderWidth = "2px"
|
||||
nameField.style.borderColor = "red"
|
||||
invalidField = true
|
||||
}
|
||||
|
||||
if(passwordField.value == ""){
|
||||
passwordField.style.borderWidth = "2px"
|
||||
passwordField.style.borderColor = "red"
|
||||
invalidField = true
|
||||
}
|
||||
|
||||
if(invalidField){
|
||||
return
|
||||
}
|
||||
|
||||
/* show the waiting dialog
|
||||
dialog = document.getElementById("waiting-dialog")
|
||||
dialog.style.disply = "block"
|
||||
setMainBackgroundOpacity(0.5)
|
||||
*/
|
||||
|
||||
/* submit the form */
|
||||
xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "/create-user");
|
||||
xhr.onload = formSubmitFinished
|
||||
formData = new FormData(document.getElementById("user-form"));
|
||||
xhr.send(formData);
|
||||
}
|
||||
|
||||
function formSubmitFinished(event){
|
||||
if(event.target.status < 200 || event.target.status >= 300){
|
||||
showErrorMessage(event.target); // blocking
|
||||
}else{
|
||||
window.location.href = event.target.responseText
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
function setMainBackgroundOpacity(opacity){
|
||||
mainContainer = document.getElementById("main-container")
|
||||
mainContainer.style.opacity = opacity
|
||||
}
|
||||
*/
|
||||
|
||||
function showErrorMessage(target){
|
||||
alert(target.responseText)
|
||||
}
|
||||
Reference in New Issue
Block a user