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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:23:22+00:00 2026-06-11T22:23:22+00:00

I have the following problem. I have a page built with (html and javascript)

  • 0

I have the following problem.

I have a page built with (html and javascript) that contains 4 checkboxes(lunch, diner, meet, rest), one input field(placename) and a go to next page button. These checkboxes and input field are all optional, they can also be left blank/unselected.

If I click the button and go to the next page there will be, genereted from javascript, a list that comes from a hardcoded json:

var myData = [ {
                 "Name" : "Bla",
                 "Placename" : "Amsterdam",
                 "lunch" : "true"
               },
               {
                 "Name" : "Bla2",
                 "Placename" : "Paris", 
                 "lunch" : "false",
                 "diner" : "true"
               },
               {
                 "Name" : "Bla3",
                 "Placename" : "London",
                 "meet" : "false",
                 "diner" : "true"
               },
               {
                 "Name" : "Bla4",
                 "Placename" : "Berlin"
               }];

The idea now is that I check which checkbox is selected and/or a placename is inserted I do this as follows:

 if(placename == ""){ 
    check json without checking placename..
 }else{
   if( ((lunchCheckbox == checked) && (element.lunch == "true")) && (Placename == element.Place)){ }

But the problem here is that now there will be many if statements, is there a way to do this better(with less statements)..

I thought about a loop but want to know if there are better ways

  • 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-11T22:23:24+00:00Added an answer on June 11, 2026 at 10:23 pm

    I think this will solve the problem:

    If you have forexample four checkboxes called: A,B,C,D. Then a solution would be to make bits of these.. so for example A = 0 or 1 B = 0 or 1 etcetera.. Then combine these bits with eachother and then you get like 0000 which would mean ABCD are all false, or 0001 only D is true. Afterwards you could save this as a string like TotalBits = “0000”. Then you do this also with the json parameters lunch=”true” = 1 and save the total bits in TotalBits2 for example, at the end you check if the bits are the same and here you go 🙂

    so for example if you code it…

    var aBit;
    var bBit;
    var cBit;
    var dBit;
    
    if(a == true){aBit="1"};
    if(b == true){bBit="1"};
    if(c == true){cBit="1"};
    if(d == true){dBit="1"};
    
    var totalBits1 = a+b+c+d; //which results in "1111"
    

    Then the same for the lunch, for example:

     var lunchBit;
     if(element.lunch == "true"){ lunchBit="1";};
     etcetera..
    
     var totalBits2 = lunchbit+dinerbit+.....; //which results in for example 1000..
    

    in the end check if totalBits1 == totalBits2 then produce result ..

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

Sidebar

Related Questions

Trying to use JSTL but have the following problem: Index.xhtml page: <?xml version=1.0 encoding=UTF-8?>
I have the following problem. I got two forms on my web page. On
I have following problem: I have built a tabbar application with 4 tabs. I
I have the following code. def add_resume_link(name, form) link_to_function name do |page| html =
I have this fragment that demonstrates the problem: <html> <head> <title>height query demo</title> <script
I have the following simple page: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
I currently have a nav menu that is built with the following, <?php if(!is_user_logged_in())
I have following problem: I have to make a ASP.NET Webapplication with a two-row
I have following problem, Code: String a=Yeahh, I have no a idea what's happening
Hi i have following Problem. I write a Mediawiki Extension where i need some

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.