Static page with a search box

I am in the process of creating a page with frequently asked questions (FAQ).

My goal is to incorporate a search box that resembles the one featured on Font Awesome Icons.

After seeking assistance online, I have managed to generate the following code:

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
</script>


<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <title>Testing a search bar</title>

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  <script src="https://use.fontawesome.com/e34d8d1dc9.js"></script>
  <script src="/Scripts/Searchbar.js"></script>
  <link href="/CSS/woff2.css" rel="stylesheet" type="text/css" />
  <link href="/CSS/site.css" rel="stylesheet" type="text/css" />
</head>

<body>
  <div class="container" data-view="search">
    <div class="row">
      <div class="col-md-10 col-sm-9">
        <section id="search">
          <label for="searchinput"><i class="fa fa-search" aria-hidden="true"></i><span class="sr-only">Search FAQ</span></label>
          <input id="searchinput" class="form-control input-lg" placeholder="Search FAQ" autocomplete="off" spellcheck="false" autocorrect="off" tabindex="1">
        </section>
      </div>
    </div>

    <div id="faqs">
      <h3>Question 1</h3>
      <section>
        Answer 1<br> abc
      </section>
      <h3>Question 2</h3>
      <section>
        Answer 2<br>xyz
      </section>
      <h3>Question 3</h3>
      <section>
        Answer 3<br>def
      </section>
    </div>
  </div>
</body>

</html>

The code references two CSS files:

  1. site.css
  2. enter link description here

and one java script file.

While the page (this is merely a test) has the desired appearance, the search feature is not functional yet.

I modeled it after a working example

Could someone assist me in making it operational as demonstrated in the example?

Answer №1

After some experimentation, I was able to successfully get it up and running. :-)

Experimenting with a search bar

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script src="https://use.fontawesome.com/e34d8d1dc9.js"></script> 
    <script src="/Scripts/FontAwesome.js"></script>

    <%--    <link href="/CSS/woff2.css" rel="stylesheet" type="text/css" />
            <link href="/CSS/site.css" rel="stylesheet" type="text/css" />
    --%>
     <link href="/CSS/woff2.css" rel="stylesheet" type="text/css" />
     <link href="/CSS/searchbar.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div class="container" data-view="search">
        <div class="row">
            <div class="col-md-10 col-sm-9">
                <section id="search">
                    <label for="searchinput"><i class="fa fa-search" aria-hidden="true"></i><span class="sr-only">Search

Frequently Asked Questions

        <div id="faqs">
            <h3>Question 1</h3>
            <section>
                Answer 1<br> abc
            </section>
            <h3>Question 2</h3>
            <section>
                Answer 2<br>xyz
            </section>
            <h3>Question 3</h3>
            <section>
                Answer 3<br>def
            </section>
        </div>
    </div>

    <script src="/Scripts/Searchbar.js"></script>
</body> </html>

By placing searchbar.js at the deepest level possible and substituting site.css with searchbar.css

Answer №2

In my opinion, a more effective approach would be implementing a versatile MVVM framework such as knockout.js. By utilizing this tool, you can consolidate all your FAQ entries into a single view model and seamlessly integrate a search feature. This method not only streamlines your HTML code but also becomes increasingly beneficial as you continue to expand your FAQ section on the website.

Answer №3

Consider organizing question objects within an array and then implementing a search filter:

Demo: https://jsfiddle.net/sjx5uorg/2/

var searchInput = $('#searchinput');
var questions = [
{
  question: "First question",
    answer: "Answer 1"
  },
{
  question: "Second question?",
    answer: "Answer 2"
  },
{
  question: "Question 3",
    answer: "Answer 3"
  },
{
  question: "Question 4",
    answer: "Answer 4"
  }
]


function updateQuestionList(questionArray) {
var questionList = $('#question-list');
questionList.html('');
$.each(questionArray, function(question) {
question = questionArray[question];
    questionList.append('<li><h3>'+ question.question +'</h3><p>'+ question.answer +'</p></li>');
});
}

updateQuestionList(questions);

searchInput.keyup(function(event) {
  var filteredQuestions = questions.filter(function(question){
  var q = question.question.toLowerCase(); 
    return q.indexOf(searchInput.val().toLowerCase()) >= 0
  });
  updateQuestionList(filteredQuestions);
});
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>

<label>
  Search: <input id="searchinput" />
</label>
<ul id="question-list"></ul>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When I click on a different area, I must rotate the arrow by 180 degrees

I am working on a project where I have implemented a select menu with an arrow that rotates 180 degrees when the menu opens. However, I need to rotate it back when clicking on another area. Below is the HTML code: `<div> <select name="sele ...

How to connect a Checklistbox within a repeater control using a LINQ data source?

In the setup of my website, I am utilizing a Repeater control which contains a CheckboxList control. The issue I am facing is that I have successfully bound the "Parameter Type" in the repeater control but the checkbox values are not displaying when I bin ...

Mapping Users to Projects in an ASP.NET MVC 5 Web Application

When attempting to assign users to my project, I encounter an error stating: "Multiple object sets per type are not supported. The object sets 'ApplicationUsers' and 'Users' can both contain instances of type 'ProjectManagementSyst ...

Issue with Bootstrap v3.3.7 panel not collapsing as expected following height adjustment

Utilizing bootstrap 3.3.7 panels, I encountered an issue when trying to slide up the panel using the icon. The panel would not hide properly once the panel height was set, resulting in only the panel content body sliding up. Here is an example: $(&apo ...

The fixed position div remains stationary as the page scrolls

Below, I am attempting to fix the position of the 'inner-navigation' div within the 'compare-display' box by making it absolutely positioned. However, when scrolling, the 'inner-navigation' div is not staying fixed. How can I ...

Design interactive elements such as buttons and input fields inspired by the layout of Google websites

Does anyone know how to achieve the sleek, lightweight buttons and text boxes seen on Google's web pages like Google Search, Google Plus, and Google Play? I am currently using JSP and CSS, but I am open to incorporating jQuery if necessary. Any help w ...

For my website's navigation bar, I utilized Bootstrap 4. Despite my efforts, I encountered difficulty in modifying the background color of the enclosing div element

After experimenting with a few different options such as setting the background-color to transparent, rgba(0,0,0,0), and background: none; I found that when I used background-color: red or any other color, the color changed as expected. Below is the HTML ...

center the view on the specified element

Utilizing ReactJs, I am developing a horizontal timeline that showcases dates. For instance, there is a list of 100 elements, each containing a date and text content. The dates are displayed horizontally using flex-direction="row" and overflowX ...

Tips on keeping display flex elements confined within a container

My goal is to add two divs to an element. The first div needs to have a fixed height and position. The second div should fill the remaining space, but not exceed it. I have created an example below to illustrate the desired result. #container { border ...

How can I show an ASP label using JavaScript?

In order to display my label when a user leaves out a field before clicking the button, I have set up this code. However, nothing happens when I click the button. What am I missing? <asp:Label ID="lblError" runat="server" Text="* Please complete all m ...

How to Assign Values to a Variable from a JSON Response in ASP.NET MVC

I am struggling with populating a variable from a JSON result in my code. I can't seem to find the right keyword to use for it. My goal is to populate this specific variable. Custom Js File var opts = [ { key: 1, label: 'High' }, { key: ...

Styling Drawn Elements on a Canvas Using CSS

Can CSS Animations be applied to a circle drawn on a canvas using JavaScript? Specifically, I am using an AngularJS directive for this purpose: https://github.com/angular-directives/angular-round-progress-directive/blob/master/angular-round-progress-direct ...

Angular components are not inheriting the Bootstrap row class as expected

Within my codebase, there are numerous controls declared in the following manner. <div class="row"> <div class="col-sm-12"> <div>Caption</div> <input type="text" class="form-control"> </div> </div> In ...

The absence of the `breakInside` rule in GrooCSS

Currently, I am utilizing GrooCSS 1.0-GA for my CSS coding needs. Regrettably, it appears that GrooCSS does not provide support for breakInside as illustrated in the code snippet below: GrooCSS.process(new Config(prettyPrint: true)) { body { breakIns ...

Tips for creating a clickable A href link in the menu bar that triggers an accordion to open in the body when clicked - html

Is there a way to open the first accordion when clicking on the "open 1st accordion" link, and do the same for the second link? The accordions themselves work perfectly fine, I just need a way to trigger them from outside their scope by clicking on links i ...

Arrangement of Divs Using CSS and HTML

Working on a New Website Hey there, I could really use some assistance in recreating the design shown in this image for my website project. I've made some progress but it's not quite coming together as expected. I'm struggling with positio ...

Expanding Images with JQuery Accordion

I'm facing a problem where I need to include accordions on my website with images, but whenever the accordion is opened, the image ends up stretched. Is there a solution to prevent this from happening? Below is the code snippet I am using: [Fiddle] ...

How to retrieve the viewstate from a child control

Is it feasible to extract data from the viewstate of a child control that is owned by a third party and for which I do not have access to the source code? ...

What are the methods for testing an Asp.net WebApplication with varying internet speeds?

Is there a way to test a web application created in Visual Studio 2008 using various internet speeds? Thank you in advance. ...

Rearrange rows in asp.net gridview by clicking buttons while maintaining sort order

I have successfully implemented a feature to move the rows of my gridview up and down with a button click by following this useful guide: However, I am facing an issue with sorting in my gridview. When the column is sorted, the rows no longer move as expe ...