JavaScript: How to redirect a page after validation
Try putting redirect in a timeout. Works like a charm
setTimeout(function() {window.location = "http://www.google.com/" });
By the way, instead of
onsubmit="return checkform(this);"
use
onsubmit="return(checkform())"
because IE doesn't like when you ommit ( and ).
How to redirect after form validation?
Put the redirect in the validation function before form.submit
How to redirect to another page after validation? And also want to pass the values to the next page
You need to use history to programmatically navigate inside your app:
import { useHistory } from 'react-router-dom';
let history = useHistory();
...
if(Username=='admin' || Username=='admin1' || Username=='admin2'){
history.push('/AdminPage');
} else {
history.push('/'); // redirect to home page
}
Form redirection after validating
Try to add a boolean
variable that becomes false
if the data is not valid like this:
$(document).ready(function() {
//This is to fill the inputs from the login form in the current registration form. Not important, this works fine.
$("#nif").val(localStorage.getItem("nif"));
$("#nombre").val(localStorage.getItem("nombre"));
$("#apellidos").val(localStorage.getItem("apellidos"));
//this is the submit button, enviar is "send".
$('#enviar').click(function(){
var valid = true;
// your validations
if($("#nif").val() == ""){
valid = false;
}
// and so on all your validations
if(valid){ // only if no errors
alert("User has been registered succesfully, will be redirected to the gallery.");
window.open("galeria.html");
}
});
});
If you want to redirect instead of opening a new window you can use:location.replace("galeria.html");
Related Topics
How to Import Modules from All Files in a Directory, Using a Wildcard
How to Write an Onclick Function for a Dynamically Generated Button
How to Access the Value of a Promise
Jquery Get Closest Td Text Value
How to Mute Video With JavaScript or Jquery
Avoid a Link to Reload the Page in JavaScript
Reprompt for Permissions With Getusermedia() After Initial Denial
Show Multiple Divs on Button Click
Save Only Date Without Timezone JavaScript
How to Add Pm or Am Based on Hour from Input
Looping Through a Json Object Containing More Objects and Arrays
How to Toggle (Hide/Show) Sidebar Div Using Jquery
How to Change the Image(Slider) One by One Every 3 Seconds in JavaScript
Typescript Property Does Not Exist on Type {}