简体   繁体   中英

How to display a message on page using javascript after clicking on submit(input type) in a form without using PHP

How to display a message after clicking on submit in javascript without using PHP.

Follow below steps

  1. create a empty div to display error like below. set initial style as display: none

Like Below

<div id="msgDiv" class="message"></div>
  1. On Submission of page just set innerHTML value to whatever message you want and display inside msgDiv div and apply style as display: block

Like Below

document.getElementById("msgDiv").innerHTML = "Message ";

There is something missing in your question (which message do you mean?), but this came me on mind:

document.querySelector("form").addEventListener("submit", function(){alert("message");});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM