my name is Om, and I'm currently trying to learn how to make a fully functional search bar where I can add and remove certain items on a whole separate page (which is the "admin" page). I currently have the prototype posted on my GitHub, so if you want to have a more in-depth look at both the code and the folder structuring, you can check it over on this link:
Currently, I have set up a value on the testSearchBar/html/apples.html folder which shows the image and description that I am planning on trying to dynamically add and remove:
header {
display: flex;
flex-direction: column;
text-align: center;
}
a {
color: black;
text-decoration: none;
}
a:hover {
color: red;
transition: 1s;
}
main {
display: flex;
flex-direction: row;
justify-content: space-around;
flex-wrap: wrap;
}
#completeCard {
display: flex;
flex-direction: column;
align-items: center;
}
#mainCard {
width: 18rem;
}
#card-desc {
margin: 0 auto;
transition: 1s;
}
<!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">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link href = '/css/apples.css' rel = 'stylesheet' type = 'text/css'>
<title>Apple Search</title>
</head>
<body>
<header>
<h1> Apples</h1>
<div id = 'apple-search-bar'>
<form class="example" action = "#">
<input type = "text" placeholder = "Search..." name = "search">
<button type = "submit"><i class = "fa fa-search"></i></button>
</form>
</div>
</header>
<main class = 'pt-5'>
<div id = 'completeCard'>
<div id = 'mainCard' class = 'card border-dark'>
<a id = 'granny-smith' href = '#'>
<img class = 'card-img-top' src = 'https://www.gardeningknowhow.com/wp-content/uploads/2019/04/granny-smith.jpg' alt = 'Granny Smith'>
<div class = 'card-body bg-secondary'>
<h3 class = 'text-center'>Granny Smith</h3>
</div>
</a>
</div>
<div id = 'card-desc' class = 'pt-2'>
<div id = 'granny-smith'>
<div class = 'card border-dark'>
<div class = 'card-body bg-secondary'>
<h6 class = 'text-center text-dark'>The granny smith is truly a wonder! This green apple may seem like a disgusting apple at first, but it's sweet and juicy taste well justifies the weird color.</h6>
</div>
</div>
</div>
</div>
</div>
</main>
</body>
<script src = '/js/apples.js'></script>
</html>
Now I also have another HTML document, testSearchBar/html/admin.html. The code is show below:
body {
width: 80%;
margin: 0 auto;
}
<!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">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<link href = '/css/admin.css' rel = 'stylesheet' type = 'text/css'>
<title>Admin Page</title>
</head>
<body>
<header>
<h1 class = 'pt-2'>Administrative Page</h1>
</header>
<main>
<form class = 'd-flex flex-column'>
<div id = 'choose-fruit' class = 'd-flex flex-row py-2'>
<h3> Choose a fruit. </h3>
<select name = 'fruits' id = "myList" required>
<option> Choose a fruit </option>
<option> Apple </option>
<option> Banana </option>
</select>
</div>
<div id = 'input-link' class = 'd-flex flex-row py-2'>
<h3> Insert image link. </h3>
<input class = 'w-50' type = 'text' id = 'link' name = 'link' required>
</div>
<div id = 'input-title' class = 'd-flex flex-row py-2'>
<h3> Insert Image Title. </h3>
<input class = 'w-50' type = 'text' id = 'title' name = 'title' required>
</div>
<div id = 'input-desc' class = 'd-flex flew-row py-2'>
<h3> Inset image description. </h3>
<input class = 'w-50' type = 'text' id = 'desc' name = 'desc' required>
</div>
<submit href = '#' class = 'mx-auto btn-primary text-center w-25' onclick = 'addImage();'><h3>Add Fruit</h3></submit>
</form>
</main>
</body>
<script src = '/js/admin.js'></script>
</html>
The first form item (#choose-fruit) is supposed to have a function that runs through all of the HTML documents, grabs the value of the website in the head (ex. <title>Apples</title>, and push its value as one of the options on the dropdown.)
The second form item (#input-link) is supposed to essentially be the image link that would be added to the selected website.
The third form item (#input-title) is supposed to give the image a title to the selected website.
And finally, the fourth form item (#input-desc) is supposed to give a description of the item in the selected website.
In short, when the submit button is pressed, it basically needs to be able to figure out which website I'm trying to add my item to, then push this line of code to the selected website (the specific form items needed are inside this line of code):
<div id = 'completeCard'>
<div id = 'mainCard' class = 'card border-dark'>
<a id = '#input-title' href = '#' onclick = 'activate();'>
<img class = 'card-img-top' src = '#input-link' alt = '#input-title'>
<div class = 'card-body bg-secondary'>
<h3 class = 'text-center'>#input-title</h3>
</div>
</a>
</div>
<div id = 'card-desc' class = 'pt-2'>
<div id = '#input-title'>
<div class = 'card border-dark'>
<div class = 'card-body bg-secondary'>
<h6 class = 'text-center text-dark'>#input-desc</h6>
</div>
</div>
</div>
</div>
</div>
Now what my issue currently is as of right now is, firstly, on how to create a function that goes through every HTML document inside of the testSearchBar/html folder, and to grab its document name and push it onto the #choose-fruit dropdown. I'm also stuck on how to create a function that adds the line of code above to the selected website, with all 3 values (link, title, and desc) pushed into their respective positions inside of this line of code.
Any tips will help me tremendously, and I will be giving an update when I figure out this problem.