Skip to content
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

15 add search input to filter students by name #22

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
22 changes: 22 additions & 0 deletions cvByUser/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<header>
<h1>Resume database</h1>
</header>
<main>

<input placeholder="e.g yaniv" id='user'type="search">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces, quotes.. use them.

<button id="searchBtn" >search</button>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you use a

element?

<h1 id="err" style="color: red"></h1>

</main>

</body>
<script src="./index.js" type="module"></script>
</html>
26 changes: 26 additions & 0 deletions cvByUser/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { users } from './usersData.js';
const URL='https://htmlpreview.github.io/?https://github.com/d-stuff/netcraft-03-2022/blob/main/'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"URL" is a native class name. Don't use this name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, use local urls. Don't put an absolute url from GitHub.

const searchButton=document.querySelector('#searchBtn')
searchButton.addEventListener('click',main)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to create a form and to listen to the "submit" event.



function searchUser(){
const userInput =document.querySelector('#user').value
const user =users.find(user=>user.name===userInput)


return user

}
function main() {
const user=searchUser()
if(user){
const urlCV=URL+user.cv
location.href = urlCV;
}
else {
document.querySelector('#err').innerHTML='User does not exist'

}

}
12 changes: 12 additions & 0 deletions cvByUser/usersData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// const URL='https://htmlpreview.github.io/?https://github.com/d-stuff/netcraft-03-2022/blob/main/'
export const users=[
{name:"ben-or",cv:'Ben-Or/BenOrHabariResume.html'},
{name:"michael",cv:'Michael/index.html'},
{name:"shaked",cv:'Shaked/index.html'},
{name:"adi",cv:'adi/index.html'},
{name:"david",cv:'david-levy/index.html'},
{name:"tal",cv:'talCv/index.html'},
{name:"yaniv",cv:'yaniv/index.html'},

]