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 3346080
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:15:41+00:00 2026-05-18T01:15:41+00:00

I have a script that I am working on that I am a little

  • 0

I have a script that I am working on that I am a little lost on.

I grab a user input (using jQuery) and then loop through an array and see if a phrase from the array exists in the user input. If it is found I am popping up an alert box telling them its found. But for some reason its not working.

Code:

submit = false;

            for(i in keyphrases_array) {
                if(english_text.indexOf(keyphrases_array[i]) != -1) {
                    if(trans_text.indexOf(keyphrases_array[i]) != -1) {
                        submit = false;
                    }
                } else {
                    submit = true;
                }
            }

keyphrases_array is a global array that is set in another function.

Example:

If in my array I have the phrase “Hello World” and my script finds Hello World in the english_text variable it then checks the user submitted text (trans_text). If the phrase is not found in trans_text then the script should return false.

  • 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-05-18T01:15:42+00:00Added an answer on May 18, 2026 at 1:15 am

    First, you shouldn’t use for/in to iterate over an array. Use a plain for loop.

    The problem is likely that the value of submit is being overwritten by the next iteration in the loop. If that’s the end of the function, you should return immediately.

    submit = false;
    
    for(var i = 0; i < keyphrases_array.length; i++) {
        if(english_text.indexOf(keyphrases_array[i]) != -1) {
              if(trans_text.indexOf(keyphrases_array[i]) != -1) {
                      // return immediately
                    return false;
              }
         } else {
               submit = true;
         }
    }
    return submit;
    

    or if there needs to be more processing, you can just break the loop:

    submit = false;
    
    for(var i = 0; i < keyphrases_array.length; i++) {
        if(english_text.indexOf(keyphrases_array[i]) != -1) {
              if(trans_text.indexOf(keyphrases_array[i]) != -1) {
                   submit = false;
                   break;
              }
         } else {
               submit = true;
         }
    }
    

    EDIT: Based on your comment, it seems that you want to return false if the text is not found in trans_text. This would meant that the test should use == instead of !=.

          if(trans_text.indexOf(keyphrases_array[i]) == -1) {
                  // return immediately
                return false;
          }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little jQuery (1.6.2) script that changes the input submit value to
I have a script that generates images from text using PHP. It's working fine
Recently started working with pointers and have created a little script that is supposed
I have a simple search script that takes user input and searches across directories
So I have been working on writing a script that takes in input from
I have this simple script that I'm working on. I must admit, I'm totally
I have a script that I'm trying to get working. Basically, what I'm trying
I have working registration script the only problem is that i do not know
I have a script that recursively loops through all the sub directories and compresses
I have a PHP script that is using get_dns_record to retrieve and display specific

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.