-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
137 additions
and
0 deletions.
There are no files selected for viewing
137 changes: 137 additions & 0 deletions
137
sqlphp/developer-notes/js/javascript (VanillaJs)/javascript - Events.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
>>>> JavaScript Events >>>>> | ||
|
||
|
||
----------------------------------------------------- | ||
Keys: Event And Form Submit, | ||
|
||
|
||
---------------------------------------------------- | ||
|
||
--------------------------------------------------------------------------- | ||
|
||
--------------------------------------------------------------------------- | ||
|
||
//Event And Form Submit: | ||
|
||
|
||
|
||
<?php | ||
|
||
include 'connection.php'; | ||
|
||
|
||
?> | ||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Bootstrap Example</title> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script> | ||
</head> | ||
<body> | ||
|
||
<div class="container"> | ||
<div class="row"> | ||
<div class="col-lg-4 offset-lg-4 py-5"> | ||
<h1>User Login</h1> | ||
<form name="myForm" action="dashboard.php" onsubmit="return formSubmit()" method="post"> | ||
<div class="py-2"> | ||
<label for="username">Username:</label><br> | ||
<input type="text" id="username" name="username" oninput="usernameValidate(this)" class="form-control" > | ||
<span class="errorUser">Username is empty</span> | ||
</div> | ||
|
||
<div class="py-2"> | ||
<label for="password">Password:</label><br> | ||
<input type="password" id="password" name="password" oninput="passwordValidate(this)" class="form-control"> | ||
<span class="errorPass">Password is empty</span> | ||
</div> | ||
<div class="py-2"> | ||
<input id="btn" type="submit" name="login" value="Login" class="btn btn-success form-control"> | ||
</form> | ||
|
||
<div class="py-2"> | ||
<button id="btn2" name="login" value="Login" onclick="checkForm()" class="btn btn-success form-control">Submit</button> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
|
||
</body> | ||
</html> | ||
|
||
|
||
|
||
<script> | ||
|
||
const errorUser = document.querySelector(".errorUser") | ||
const errorPass = document.querySelector(".errorPass") | ||
|
||
const username = document.querySelector('#username') | ||
const password = document.querySelector('#password') | ||
|
||
//Submit Form | ||
function formSubmit(){ | ||
if(username.value == ""){ | ||
username.style.border = "1px solid red" | ||
errorUser.style.display = "block" | ||
return false | ||
} | ||
if(password.value == ""){ | ||
password.style.border = "1px solid red" | ||
errorUser.style.display = "block" | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
//User Validate | ||
function usernameValidate(ele){ | ||
|
||
if(ele.value == ""){ | ||
ele.style.border = "1px solid red" | ||
errorUser.style.display = "block" | ||
return false | ||
}else{ | ||
ele.style.border = "1px solid blue" | ||
errorUser.style.display = "none" | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
//Password Validate | ||
function passwordValidate(ele){ | ||
|
||
if(ele.value == ""){ | ||
ele.style.border = "1px solid red" | ||
errorPass.style.display = "block" | ||
return false | ||
}else{ | ||
ele.style.border = "1px solid blue" | ||
errorPass.style.display = "none" | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
|
||
</script> | ||
|
||
|
||
<style> | ||
.errorUser {display:none; color:red;} | ||
.errorPass {display:none;color:red;} | ||
</style> | ||
|
||
|
||
----x---- | ||
---------------------------------------------------------------------------------- |