0

I am trying to make paragraph 1 show on a certain list of pages and paragraph 2 show on the pages not mentioned. The problem is, that I am seeing paragraph 2 on all pages.

This is not my code I was asked to make adjustments to already existing code and I am not very savvy with JS so please forgive my ignorance. Any help is greatly appreciated and thanks for reading.

Code:

if ((querystring('category') == '1')
    && (querystring('category') == '2')
    && (querystring('category') == '3')
    && (querystring('category') == '4')
    )
{
    var productContent = $('div#catalogContainer').html();
    var textContent = "<p>Paragraph 1</p>"
    $('div#catalogContainer').html(productContent + textContent);


}
else 
{
    var productContent = $('div#catalogContainer').html();
    var fullTextContent = "<p>Paragraph 2</p>"
$('div#catalogContainer').html(productContent + fullTextContent);
3
  • Your question is still unclear. What is your question actually? I don't see syntax issues here. Commented Sep 11, 2014 at 2:04
  • Sorry should have clarified. I am seeing paragraph 2 on all pages. Commented Sep 11, 2014 at 2:10
  • that depends on what querystring('category') returns. Please show the function. Commented Sep 11, 2014 at 2:12

1 Answer 1

2

Assuming the result of querystring('category') doesn't change each time it's called, you want to use || instead of &&.

Your if statment is basically asking if all of those things are true. If querystring('category') is simultaneously equal to '1', '2', '3', and '4', then show paragraph 1, otherwise show paragraph 2. Which may explain why paragraph 2 is always shown, since one thing can't be equal to all four of those at the same time.

If you change to || instead, you're asking if querystring('category') is equal to at least one of those four things, instead of all four of them at the same time.

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

Comments

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.