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

  • Home
  • SEARCH
  • 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 7307945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T23:29:26+00:00 2026-05-28T23:29:26+00:00

I have JavaScript that takes the entry from a form and then searches the

  • 0

I have JavaScript that takes the entry from a form and then searches the location after using “GET” to apply these form inputs to values, as you can see it ends up with me using a for statement couple by a very long if/else if statement. What is the best way to make this more efficient?

Thank you!

var search = location.search;
var parts = search.slice(1).split('&');    // Need to slice to remove initial '?'
for (var i=0; i < parts.length; ++i)
{
  var info = parts[i].split('=');
  var variable = info[0];
  var value = info[1];
  if(variable === "pNAME") {
            var pNAME = value;      
  }
  else if(variable === "mAB") {
            var mAB = value;      
  }
  else if(variable === "mPB") {
            var mPB = value;      
  }
  else if(variable === "mNA") {
            var mNA = value;      
  }
  else if(variable === "lPED") {
            var lPED = value;      
  }
  else if(variable === "lSS") {
            var lSS = value;      
  }
  else if(variable === "lSC") {
            var lSC = value;      
  }
  else if(variable === "lVIS") {
            var lVIS = value;      
  }
  else if(variable === "lPAR") {
            var lPAR = value;      
  }
  else if(variable === "lBUS") {
            var lBUS = value;      
  }
  else if(variable === "lTRAIN") {
            var lTRAIN = value;      
  }
  else if(variable === "cHT") {
            var cHT = value;      
  }
  else if(variable === "cRAM") {
            var cRAM = value;      
  }
  else if(variable === "cTMS") {
            var cTMS = value;      
  }
  else if(variable === "cCC") {
            var cCC = value;      
  }
  else if(variable === "cCG") {
            var cCG = value;      
  }
  else if(variable === "cSTRL") {
            var cSTRL = value;      
  }
  else if(variable === "cWEAL") {
            var cWEAL = value;      
  }
  else if(variable === "deWHI") {
            var deWHI = value;      
  }
  else if(variable === "deASI") {
            var deASI = value;      
  }
  else if(variable === "deBLA") {
            var deBLA = value;      
  }
  else if(variable === "deOTH") {
            var deOTH = value;      
  }
  else if(variable === "daYOU") {
            var daYOU = value;      
  }
  else if(variable === "daYM") {
            var daYM = value;      
  }
  else if(variable === "daM") {
            var daM = value;      
  }
  else if(variable === "daOL") {
            var daOL = value;      
  }
  else if(variable === "doPOP") {
            var doPOP = value;      
  }
  else if(variable === "doDENS") {
            var doDENS = value;      
  }
  else if(variable === "doSTU") {
            var doSTU = value;      
  }
};

Thank you in advanced!

  • 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-28T23:29:26+00:00Added an answer on May 28, 2026 at 11:29 pm

    You could make an object out of it and assign the variable as property, using the variable
    name as property name. Something like:

      var myVar = {};
      for (var i=0; i < parts.length; ++i){
        var info = parts[i].split('=');
        myVar[info[0]] = info[1];
      }
    

    Now you have all your variables and values in one Object, addressable for example as myVar.lSS or myVar.pNAME.

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

Sidebar

Related Questions

I have a JavaScript function that takes two required parameters and then arbitrarily many
I have some JavaScript that on button click takes a the text from the
i have a javascript method that takes a date: convert(new Date(02/20/2010); how can i
I have a javascript function (class) that takes a function reference as one paremter.
I have some javascript that I'm trying to retool using jQuery to learn the
I have a simple javascript function that takes two variables. I need to pass
I have this function that takes some user-submitted HTML code from the database: function
I have a JavaScript API that has a function x that takes some parameters
Let's say I have a javascript method that takes a little to long to
So I have a JavaScript method that is ran after a user selects certain

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.