0

On my web app, the user is asked a question and can choose only one of two answers. Yes or no. A query string is created based on their answer.

The following code carries the query string through the URL of every page:

var navlinks = document.getElementsByClassName("qString");
    $(navlinks).prop("href", function() { return this.href + location.search; })

There are only 2 query strings, ?choice=yes and ?choice=no.

Once the user is taken through the app, if they navigate to either park01.html, park02.html, or park03.html from any other page, data will be pulled accordingly via a called function().

Here's my concept in pseudocode:

// I assume I should store specific html pages to a variable    
var parkPages = ["park01.html", "park02.html", "park03.html”];

    if (user clicks on specified html pages stored in variable) {

         and the url contains = ?choice=yes;
         Then call these functions: funcA(), funcB(), funcC();
    }
    else {

         the url contains = ?choice=no;
         Then call these functions: funcD(), funcE(), funcF();
    }

Does the concept make sense? And what does the syntax look like?

7
  • 1
    What is onClick parkPages? What syntax? Commented Apr 30, 2015 at 21:11
  • I'm working in JavaScript. And the above concept is written in JS pseudocode. Commented Apr 30, 2015 at 21:16
  • 1
    How is the user "taken through the app"? Commented Apr 30, 2015 at 21:17
  • You surely want location.pathname, not location.search? Commented Apr 30, 2015 at 21:17
  • I've never worked with query strings before so this is new to me. I want to call a specific function based on the query strings generated on the index.html page. @Bergi The user navigates through the app using the global nav bar. That's what I meant by "taken." Commented Apr 30, 2015 at 21:23

1 Answer 1

2

If you're simply looking for a concrete translation of your pseudocode into JavaScript, based on your last comment, this should be what you need:

if (location.search === "?choice=yes") {
    funcA();
    funcB();
    funcC();
}
else {
    funcD();
    funcE();
    funcF();
}

Though at this stage, I'd recommend spending less time here and more on instructional/tutorial based websites.

Sign up to request clarification or add additional context in comments.

1 Comment

I appreciate the answer. I'm doing the instruction/tutorial sites as well, but said sites can't answer my questions. I've learned recently that I've had the answer to JS problems but didn't have the confidence to trust my knowledge.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.