How to display the html div so that after form submit the error messgae is displayed automatically

how to display error message in html form
javascript form validation with all error messages at once
how to display error message in html form bootstrap
how to show error message in html5
how to display error message below textbox using javascript
javascript form validation with error message
submit error message
how to display error message in html form using php

I have a form that validates whether the username and password is correct or not but it does not show the error messages unless i click on the form again.The form is inside a html div tag, I want to know how to style the div with css so that the error messages can be displayed automatically after form submit. Here is my code

<h3 class="registration-header">
Log in. </h3>
<div class="registration-box-info"><span>
Please enter username and password  </span></div>
<form action="/" charset="UTF-8" method="post">
            <div class="error-message alert-danger">
        <span>Sorry, unrecognized username or password.<a href="#">Have you forgotten your password?</a></span>
    </div>

The error message is not displayed automatically after inserting wrong input and so I would be grateful if you can tell me how to style the div using css to make it visible after submitting wrong input

If you want to do it without js, you could use

:valid 
:invalid 

CSS pseudo class and style the border of the input accordingly.

You could also attach a pattern to the validation.

Check: https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Form_validation

How to display the html div so that after form submit the error , The form is inside a html div tag, I want to know how to style the div with css so that the error messages can be displayed automatically after form submit. Here is​  Display "Form sent successfully!" on same page of the form after form submission. I'm working on a contact form. It's working fine. User fills up contact form, processed by PHP, if successful, the user will be redirected to a thank you page then will redirect back to the main webpage after 3 or so seconds.

For checking wheather username and other filed are empty or not, you have to just add required inside the tag like <input type="text" name="full-name" id="full-name" placeholder="Name" required /> An for validation visit https://www.w3schools.com/js/js_validation.asp

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: #eee;
  font-family: 'helvetica neue', helvetica, arial, sans-serif;
  color: #222;
}

#form {
  max-width: 700px;
  padding: 2rem;
  box-sizing: border-box;
}

.form-field {
  display: flex;
  flex-wrap: wrap;
  margin: 0 0 1rem 0;
}
label, input {
  width: 70%;
  padding: 0.5rem;
  box-sizing: border-box;
  justify-content: space-between;
  font-size: 1.1rem;
}
label {
  text-align: right;
  width: 30%;
}
input {
  border: 2px solid #aaa;
  border-radius: 2px;
}
.error-message {
    flex: 0 0 100%;
    margin-left: 30%;
    color: red;
}
<form method="post" action="/" id="form" class="validate">
  <div class="form-field">
    <label for="full-name">Full Name</label>
    <input type="text" name="full-name" id="full-name" placeholder="Name" required />
  </div>
  <div class="form-field">
    <label for="email-input">Email</label>
    <input type="email" name="email-input" id="email-input" placeholder="test@gmail.com" required />
  </div>
  <div class="form-field">
    <label for="password-input">Password</label>
    <input type="password" name="password-input" id="password-input" required />
  </div>
  <div class="form-field">
    <label for=""></label>
    <input type="submit" value="Sign Up" />
  </div>
</form>

HTML5 Form Validation - Showing All Error Messages, HTML5 Form Validation - Showing All Error Messages has errors on multiple fields, the browser will only display the first error to Both fields are required , but if you submit the form you will only see an error for the first field. If you've ran into a form such as this before you know what I'm talking about. If you want to do it without js, you could use :valid :invalid CSS pseudo class and style the border of the input accordingly. You could also attach a pattern to the validation.

If you can use jquery, and if you want customise your kind of error,

like, if you enter, 'map', derive' or 'glossary, you have different message. If you enter '???' or anything else you'll have your message 'Sorry, unrecognized...'

You can use :

<!DOCTYPE html>
<html>
<head>
<style>
  #div1   {background-color: red;}
  #div2   {background-color: blue;}
  #div3   {background-color: black;
    color: white;}
  #error   {background-color: red;}
</style>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>

<h3 class="registration-header">
Log in. </h3>
<div class="registration-box-info"><span>
Please enter username and password  </span></div>
<!-- form action="/" charset="UTF-8" method="post" -->
<input type="text" placeholder="ENTER COMMAND" />

<div id="div1">div1 : you entered the log 'map'</div>
<div id="div2">div2 : you entered the log 'derive'</div>
<div id="div3">div1= : you entered the log 'glossary'</div>
<div id="error"><span>Sorry, unrecognized username or password.<a href="#">Have you forgotten your password?</a></span></div>
 

<script>
$(document).ready(function() {

  // Hide both <div> by default
  $('#div1').hide();
  $('#div2').hide();
  $('#div3').hide();
  $('#error').hide();

  // Check on keydown
  $('input').keyup(function (e) {
    if (e.keyCode == 13) {
      var value = $(this).val();
      $('#div1').hide();
      $('#div2').hide();
      $('#div3').hide();
      $('#error').hide();
      if (value == 'map') { // If input value is div1
        $('#div1').slideDown();
      } else if (value == 'derive') { // If input value is div2
        $('#div2').slideDown();
      } else if (value == 'glossary') { // If input value is div3
        $('#div3').slideDown();
      } else if (value != '') { // If input value is wrong
        //$('#error').html(value + " is an incorrect input value");
        $('#error').slideDown();
      }
    }
  });
});
</script>

</body>
</html>

User Notifications • Forms • WAI Web Accessibility Tutorials, Provide feedback to users about the results of their form submission, whether In particular, error messages should be easy to understand and should provide A message is displayed in the dialog box, and the web page is disabled until be inserted into a prominent container on the top to inform the user in such a case. I will be very glad if I can get a tip on how I can display success message after form submission with changing URL in PHPjust the idea to start off

WebD2: Using Javascript to Hide and Show Content, For example, a user may select an option when filling out an on-line form, and their In this lesson, you will use CSS and Javascript to show and hide the clock that you've created. Open javascript.html in both your text editor and web browser. If the display is currently set to "block", the clock is visible, so you change the  Learn how to create alert messages with CSS. Alert messages can be used to notify the user about something special: danger, success, information or warning. Indicates a dangerous or potentially negative action. Indicates a successful or positive action. Indicates a neutral informative change or action. Indicates a warning that might need attention.

Client-side form validation, So why do we insist on validating our forms? This is done by using validation attributes on form elements. Find the source code on GitHub at fruit-start.html and a live example below. UI pseudo-class and the form won't submit, displaying an error message on submission when the input is empty. IT issues often require a personalized solution. With Ask the Experts™, submit your questions to our certified professionals and receive unlimited, customized solutions that work for you.

How to make inline error messages accessible, If an input error is automatically detected, the item that is in error is In the old days, a form submit would just trigger the same page to reload, now be hugely enhanced by preventing the submit and displaying errors client side. in many ways (see PPK's 3 part article on form validation), so in this article I  Everything works except that i want to display a message on the same page when the user clicks 'update' without loading to another page. like you click 'submit' and instantly a message next to the button comes up saying 'the form has been updated', and i want to disappear the moment the user reloads the form.

Comments
  • you need to learn a bit of js to make your validation show - or use html 5 error attributes
  • you can use jquery validation jqueryvalidation.org
  • vist css-tricks.com/form-validation-ux-html-css for getting basics of forms and validations with demo
  • The validation are working fine but the error message is not visible automatically.The error messga e can only be seen after clicking the register button again.I wanted to know is there anything I can do with the div styling so that the content (error message)inside the div is visible after form submit.
  • The validation is working fine.I only want to show div class="error-message alert-danger"> <span>Sorry, unrecognized username or password.<a href="#">Have you forgotten your password?</a></span> </div> automatically after submitting wrong username and password
  • Thanks Gregor.I already have the validation but want to show the error messages automatically after submitting the form if the username and password is incorrect.
  • Thank you very much but I wanted to share that The validation are working fine but the error message is not visible automatically.The error messga e can only be seen after clicking the register button again.I wanted to know is there anything I can do with the div styling so that the content (error message)inside the div is visible after form submit
  • Thanks alex.I did the validation.I want to only know how to display the error messages automatically by styling the div tag in html using css.
  • You can add a style tag before the body where you can styling the div tag. I modified the code for give you an example. If i helped you, thanks to up vote or validate to inform others :)
  • Thank you very much alex..it almost fixed my problem..but here the div is declared inside the file, I wanted to know what can i do for the username and password that will be checked from the database.I mean how to give error message for wrong username and password .I would really be thankful if you can give me some guidance
  • If you want to stay on same page if validation fails, it is something like that you want : link, but i can't test without your database (posgres, mysql, the tables, the columns, how you access it...). I added another snippet witch use ajax and php, but i can't make it return on the page because it is not my server. You have to try with your own page name : something.php an fill the ajax part for your server. My answer have no vote, don't forget to up vote or validate.
  • Thank you again alex...i will try to run it in my page and hopefully it will work..Thanks