0

Im creating a form and in this form I want a message to be displayed when the user clicks the submit button. Can this be done without php?

3
  • Without php - use javascript. Commented Nov 6, 2016 at 12:33
  • 1
    What kind of message do you want to display? A message in an alert box? Or just simply display a message in a custom div? If you want to display an alert box you can do it like this: <input type="submit" onclick="alert('The submit button was pressed'); return false;"> Commented Nov 6, 2016 at 12:38
  • Thanks! :D @pappfer Commented Nov 6, 2016 at 12:44

1 Answer 1

1

Instead of an input element with type="submit", consider using a normal button with an onclick attribute. Do not specify any action attribute for the <form> element.

<form>
  <input id="usn" type="text" placeholder="Username" />
  <input id="psw" type="text" placeholder="Password" />
  <input type="submit" onsubmit="myFunction()" />
</form>
<script type="text/javascript">
  function myFunction() {
    var username = "The username you entered is: " + document.getElementById('usn').value + ". ";
    var password = "The password you entered is: " + document.getElementById('psw').value + ". ";
    alert(username + password);
  }
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.