-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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"> | ||
<button id="searchBtn" >search</button> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
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/' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "URL" is a native class name. Don't use this name. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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' | ||
|
||
} | ||
|
||
} |
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'}, | ||
|
||
] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces, quotes.. use them.