Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8643399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:01:31+00:00 2026-06-12T12:01:31+00:00

In the code below I have a form input. When the user searches for

  • 0

In the code below I have a form input. When the user searches for a string that happens to be in the array I want it to output the query. When a user happens to search for a string not in the array I want to output an error message. The problem is when a user searches for a string that is other than item [0] in the array (in this case ipsum) they get an error message and then they get their query returned. I want to know if this can be remedied using the code below or if a different methodology for doing this should be pursued ( I know that’s an opinion ).

<form>
<input type="text" id="formInput"></input>
<input type = "button" id="search"></input>

</form>


<script>


var search = document.getElementById("search");


var data = ["lorim", "ipsum"];

search.onclick = function(){
var formInput = document.getElementById("formInput").value;
for (i=0; i<data.length; i++){

    if (data[i] === formInput) {

      alert(data[i]);
    }   
      else{ alert("not working yet");   }
}
};

</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:01:34+00:00Added an answer on June 12, 2026 at 12:01 pm

    you don’t need a loop, just use indexOf:

    search.onclick = function(){
        var formInput = document.getElementById("formInput").value;
    
        if (data.indexOf(formInput) === -1) {
            // they entered a bad search term
            return;
        }
    
        // do the rest of your search logic
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the code below on form so that the user submits the form
I have a form (code below) that allows a user to upload an image
I have below html code in one of the opensource project. <form action=/wiki/bin/view/Main/Search> <div
I want to make a CListView that remembers search form input. My application saves
I have the below code working onclick. <form action= name=testform method=post id=testform> <input type=hidden
I have a form to signup with the code below: <form method=post> Username<input type=text
I have a real basic form (code below) with a bunch of back-panel PhP.
I have below code: class Program { static void Main(string[] args) { Task[] tasks
I have a form with a Jquery plugin requirement that creates a form input
I have a form that the user is going to interact with, by updating,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.