-1

So I have this quiz with two separate start files. Then I have javascript that takes the url argument ?type=ohs and ?type=dls and display certain images depending on the argument. I then have a complete page. People with the ?type=dls argument get a link that takes them somewhere else, and people with ohs get just some confirmation text. I want it to be contained on the same complete page, but I am having a hard time trying to figure it out. The javascript I have is:

function go_to_url(page_name) {
  location.href = page_name + "?" + location.href.split('?')[1];
}

That is to display images depending on the url argument. How do I create the javascript for the complete page that will display certain text or a link depending on the url arguments ?type=ohs and ?type=dls?

James Montagne
  • 77,516
  • 14
  • 110
  • 130
  • what exactly is your question? do you want us to write the code for the whole site, or..? – mb21 Jun 28 '13 at 17:39
  • No I am just lost. I have two start pages and 5 of the same HTML pages. Depending on the start page it attaches a url argument, and displays different images. I have one complete page that gets one of the two arguments attached to it. Depending on the URL argument for the complete page, I want to display 2 different types of text depending on the argument of the complete page. How exactly do I do it? – user2532765 Jun 28 '13 at 17:44

1 Answers1

0

It sounds like you want to get values from the query string

here is a function to do that:

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

Taken from the answer to this question How can I get query string values in JavaScript?

var v = getParameterName("type"); //Will return ohs or dls
if(v == "ohs")
    //display text for ohs
else
    //display text for dls
Community
  • 1
  • 1
Eric Beaulieu
  • 1,054
  • 7
  • 11
  • I already have a function that attaches the correct url arugment (either dls or ohs). Theres only one complete page but two arguments, say www.complete.com?type=ohs and complete.com?type=dls. For dls I want to display a specific text and for ohs another type of text. – user2532765 Jun 28 '13 at 17:52
  • This function doesnt attach a url argument it gets it's value, running getParameterName("type") in www.complete.com?type=ohs will return ohs and it will return dls in www.complete.com?type=dls – Eric Beaulieu Jun 28 '13 at 17:58
  • Oh okay, so how to I display the text depending on the OHS or DLS in the url argument? – user2532765 Jun 28 '13 at 18:01
  • I don't understand what you want, you want us to show you how to do an if statement? You want us to show you how to display text? – Eric Beaulieu Jun 28 '13 at 18:03
  • I guess so. I need to display text depending on the ?type=ohs or dls in the url. I am completely new to javascript, but our homework is crazy complicated and Ive spent hours and cant find an answer. – user2532765 Jun 28 '13 at 18:05
  • This site is more for specific questions. Try to do your homework and ask if you get stuck with a technical detail. There are many ways to do what you are asking, too many. You are asking 3 questions how do I get query string values (I already answered that), how do I do an if statement on a string (it's pretty simple, I did add it to my answer) and last how do I display text from javascript? (a quick search on google will answer that) – Eric Beaulieu Jun 28 '13 at 18:14