• Exclusive

    Hey Guest, unlock an instant 10% bonus discount when you upgrade via the Crypoverse gateway.

HTML form with JavaScript validation (1 Viewer)

Currently reading:
 HTML form with JavaScript validation (1 Viewer)

Recently searched:

arobnu62

Member
LV
0
Joined
Jul 19, 2023
Threads
2
Likes
0
Credits
190©
Cash
0$
Here's a simple script for an HTML form with JavaScript validation. It can be used to learn form validation.


<!DOCTYPE html>
<html>
<head>
<title>Simple Form Validation</title>
<script type="text/javascript">
function validateForm() {
var x = document.forms["myForm"]["fname"].value;
if (x == "" || x == null) {
alert("Name must be filled out");
return false;
}
}
</script>
</head>
<body>

<form name="myForm" action="/submit_form" onsubmit="return validateForm()" method="post">
Name: <input type="text" name="fname">
<input type="submit" value="Submit">
</form>

</body>
</html>

In this script, if you try to submit the form without entering a name, an alert box with the message "Name must be filled out" will appear, and the form won't be submitted until a name is provided.

Please replace "/submit_form" with your own server endpoint. This is where the form data will be sent when the form is submitted.
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Tips
Recently searched:

Similar threads

Users who are viewing this thread

Top Bottom