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?
1 Answer
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>
<input type="submit" onclick="alert('The submit button was pressed'); return false;">