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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:53:38+00:00 2026-06-09T15:53:38+00:00

I am currently designing a GUI that allows the user to define some logic.

  • 0

I am currently designing a GUI that allows the user to define some logic. I don’t want it getting too complex, so I am limiting it to a single set of brackets. So, the idea is to check that between the opening and closing brackets there are not any other opening brackets.

eg. IF ( a + b OR **(** b+ c) would alert with error.

So I decided with the route of:

  • Find the first open bracket
  • Find the first close bracket
  • Using those indices search between and find any open brackets
  • If any open brackets are found display an error
  • Continue the loop for any other logic

Here’s the code. I think its pretty horrific and I am sure there must be a better way to do this. Some kind of IndexOf maybe.

<select rel="OpenBracket" id="open1">
    <option value=""></option>
    <option value="(">(</option>
</select>
Some True/Fale here
<select rel="CloseBracket" id="close1">
    <option value=""></option>
    <option value=")">)</option>
</select>
AND
<br />
<select rel="OpenBracket" id="open2">
    <option value=""></option>
    <option value="(">(</option>
</select>
Some True/Fale here
<select rel="CloseBracket" id="close2">
    <option value=""></option>
    <option value=")">)</option>
</select>
<button onclick="javascript:TestingRules();">Check</button>

function GetOpenBrackets() {
    var openBracketArray = [];
    jQuery('[rel="OpenBracket"]').each(function() {
        if (jQuery(this).val() == "(") {
            openBracketArray.push(jQuery(this).attr('id'));
        } else {
            openBracketArray.push(jQuery(this).val());
        }

    });
    return openBracketArray;
}

function GetCloseBrackets() {
    var closeBracketArray = [];
    jQuery('[rel="CloseBracket"]').each(function() {
        if (jQuery(this).val() == "(") {
            closeBracketArray.push(jQuery(this).attr('id'));
        } else {
            closeBracketArray.push(jQuery(this).val());
        }
    });
    return closeBracketArray;
}
function TestingRules() {
    var openBrackets = GetOpenBrackets();
    var closeBrackets = GetCloseBrackets();
    var closeBracketIndex;
    var openBracketIndex;
    for (openBracketIndex in openBrackets) {
        if (openBrackets[openBracketIndex] !== "") {

            var foundCloseBracketIndex = -1;
            for (closeBracketIndex in closeBrackets) {
                if (openBracketIndex <= closeBracketIndex) {
                    if (closeBrackets[closeBracketIndex] !== "") {
                        foundCloseBracketIndex = closeBracketIndex;
                        break;
                    }
                }
            }
            if (foundCloseBracketIndex > -1) {
            var openBracketCheck;
                for (openBracketCheck in openBrackets) {

                    if (openBracketIndex < openBracketCheck && closeBracketIndex >= openBracketCheck) {
                        if (openBrackets[openBracketCheck] !== "") {
                            alert('error');
                        }
                    }

                }
            }
        }

    }

    // for testing:
    //  console.log(OpenBracketArray.length);
}
  • 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-09T15:53:39+00:00Added an answer on June 9, 2026 at 3:53 pm

    Why not just keep a counter, or count paren stack depth? If you inc for open parens, dec for closing, and the counter goes above 1, you have an error. (If I’ve understood your requirements correctly.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently designing an API where I want that the user to be
I'm currently designing a program that will involve some physics (nothing too fancy, a
I'm currently designing an architecture for a web-based application that should also provide some
We are currently designing a REST API that we want to publish in a
I'm currently designing a complex website that needs to support Undo and Notifications for
I am currently designing a GUI to control some software. I am using fltk,
I am currently designing a website in C#, which uses some very complex code
I'm currently in the process of designing and developing GUI's for some audio applications
I'm currently designing a system that watches the ranks / views of youtube videos.
I'm currently designing an app that calls for dynamically creating objects and then displaying

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.