when i press enter on the search bar its going all blank or saying file doesn’t exist. how do i fix it. it is also Khan Academy.
HTML
<form id="Search" onsubmit="Search()">
<input type="text" id="Search-bar" placeholder="Search or type a URL"
onclick="this.select();"
onfocus="this.placeholder = ''"onblur="this.placeholder = 'Search or type a URL'">
<input type="submit" id="Search-Button" >
</form>
<div id="Website1">
<h1>asasgdajs</h1>
</div>
JavaScript
var input = document.getElementById("Search-bar");
input.addEventListener("keypress", function(event) {
if (event.key === "Enter") {
event.preventDefault();
document.getElementById("Search-Button").click();
}
});
function Search() {
var x = document.getElementById('Search-bar').value;
if (x == "" || x == null) {
return false;
}
else if (x=== "website.com")document.getElementById('Website1').style.display = "block";
else {return true;}
}
CSS
#Search-bar {
position: absolute;
top: 38px;
width: 90%;
height: 12px;
border:none;
background-color:rgb(236, 239, 247);
border-radius: 25px;
padding: 6px;
font-size: 14px;
margin-bottom: 10px;
transition: background-color 0.3s ease-out;
}
#Search-bar:hover {
background-color:rgb(220, 223, 232);
}
#Search-bar:focus {
background-color:rgb(255, 255, 255);
outline: none !important;
border:1.5px solid blue;
position:absolute;
top: 37px;
left:7px;
}
#Website1{display:none;}
#Search-Button{display:none;}
If you want the rest of the code:
https://www.khanacademy.org/computer-programming/browser-v01/5205239442096128?width=786&height=650