<!doctype html>
<
html
lang
=
"en"
>
<
head
>
<
meta
charset
=
"utf-8"
>
<
meta
name
=
"viewport"
content
=
"width=device-width, initial-scale=1"
>
<
title
>Horizontal Form</
title
>
<
link
rel
=
"stylesheet"
href
=
integrity
=
"sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH"
crossorigin
=
"anonymous"
>
</
head
>
<
body
>
<
div
class=
"container-fluid bg-success d-flex
justify-content-center align-items-center"
style
=
"min-height: 100vh;"
>
<
div
class
=
"container"
>
<
h2
>Horizontal Form</
h2
>
<
form
class
=
"form-horizontal"
id
=
"myForm"
onsubmit
=
"return validateForm()"
>
<
div
class
=
"form-group row mt-5 mb-3"
>
<
label
class
=
"col-sm-2 col-form-label fw-bold"
for
=
"inputName"
>
Name:
</
label
>
<
div
class
=
"col-sm-10"
>
<
input
type
=
"text"
class
=
"form-control"
id
=
"inputName"
placeholder
=
"Enter your name"
>
</
div
>
</
div
>
<
div
class
=
"form-group row mb-3"
>
<
label
class
=
"col-sm-2 col-form-label fw-bold"
for
=
"inputEmail"
>
Email:
</
label
>
<
div
class
=
"col-sm-10"
>
<
input
type
=
"email"
class
=
"form-control"
id
=
"inputEmail"
placeholder
=
"Enter your email"
>
</
div
>
</
div
>
<
div
class
=
"form-group row mb-3"
>
<
label
class
=
"col-sm-2 col-form-label fw-bold"
for
=
"inputPassword"
>
Password:
</
label
>
<
div
class
=
"col-sm-10"
>
<
div
class
=
"input-group"
>
<
input
type
=
"password"
class
=
"form-control"
id
=
"inputPassword"
placeholder
=
"Enter your password"
>
<
button
class=
"btn btn-outline-secondary
bg-primary border-primary text-light"
type
=
"button"
id
=
"togglePassword"
>
Show
</
button
>
</
div
>
</
div
>
</
div
>
<
div
class
=
"form-group row mb-3"
>
<
label
class
=
"col-sm-2 col-form-label fw-bold"
for
=
"inputMessage"
>
Message:
</
label
>
<
div
class
=
"col-sm-10"
>
<
textarea
class
=
"form-control"
id
=
"inputMessage"
rows
=
"3"
placeholder
=
"Enter your message"
></
textarea
>
</
div
>
</
div
>
<
div
class
=
"form-group row"
>
<
div
class
=
"col-sm-10 offset-sm-2"
>
<
button
type
=
"submit"
class
=
"btn btn-primary"
>
Submit
</
button
>
</
div
>
</
div
>
</
form
>
</
div
>
</
div
>
<
script
src
=
integrity
=
"sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
crossorigin
=
"anonymous"
>
</
script
>
<
script
>
document.getElementById("togglePassword").
addEventListener("click", function () {
const passwordInput =
document.getElementById("inputPassword");
if (passwordInput.type === "password") {
passwordInput.type = "text";
this.textContent = "Hide";
} else {
passwordInput.type = "password";
this.textContent = "Show";
}
});
function validateForm() {
const name =
document.getElementById("inputName").value.trim();
const email =
document.getElementById("inputEmail").value.trim();
const password =
document.getElementById("inputPassword").value.trim();
const message =
document.getElementById("inputMessage").value.trim();
if (name === "" ||
email === "" ||
password === "" ||
message === "") {
alert("Please fill in all fields.");
return false;
}
if (!email.includes("@")) {
alert("Please enter a valid email address.");
return false;
}
if (password.length <
8
) {
alert("Password must be at least 8 characters long.");
return false;
}
return true;
}
</script>
</
body
>
</
html
>