Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

DOM-Form #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions JavaScript/Advance/DOM/5. DOM Form/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
h2 {
font-family: monospace;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions JavaScript/Advance/DOM/5. DOM Form/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DOM FORM</title>
<link rel="stylesheet" href="css/style.css">
</head>

<body>
<h1>Javascript Form Validation</h1>
<h2>Example One</h2>
<form name="myForm" action="/action_page.php" onsubmit="return validateForm()" method="post">
Name: <input type="text" name="fname">
<input type="submit" value="Submit">
</form>
<h2>Example Two</h2>
<p>Please input a number between 1 and 10:</p>

<input id="numb">

<button type="button" onclick="FunctionOne()">Submit</button>

<p id="textOne"></p>
<script src="script.js"></script>
</body>

</html>
25 changes: 25 additions & 0 deletions JavaScript/Advance/DOM/5. DOM Form/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Example One
function validateForm() {
let x = document.forms["myForm"]["fname"].value;
if (x == "") {
alert("Name must be filled out");
return false;
}
}


//Example Two
let textOne = document.getElementById('textOne');

function FunctionOne() {
// Get the value of the input field with id="numb"
let x = document.getElementById("numb").value;
// If x is Not a Number or less than one or greater than 10
let text;
if (isNaN(x) || x < 1 || x > 10) {
text = "Input not valid";
} else {
text = "Input OK";
}
textOne.innerHTML = text;
}