Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Slight Adjustment To Code!

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #207712
    mo_da92
    Participant

    Hi,

    I hope someone can help me with this. I am basically trying to create a landing page where people will need to enter a code. There are 3 different codes. Depending on the code they enter, they will be redirected to specific pages.

    The closes code I have found that does something like this is found on this page:http://jsbin.com/ifupix/1/edit?html,output

    It does pretty much exactly what I went EXCEPT this only works for 1 page e.g. the right page and the wrong page. I tried adding a second page e.g.

    var response = document.getElementById('answer').value;
    if (response == "correctanswer")
    location = 'http://jsbin.com/ukifoh/1'; // 'right.html';
    if (response == "correctanswer2")
    location = 'http://jsbin.com/ukifoh/1'; // 'right.html';
    else
    location = 'http://jsbin.com/ukifoh/2'; // 'wrong.html';

    but all this does is that ‘correctanswer2’ works and ‘correctanswer’ does not work.

    This is what I am trying to achieve:

    correctanswer will redirect to right page.
    correctanswer 2 will redirect to right page 2.
    correctanswer 3 will redirect to right page 3.
    anything else will redirect to wrong page.

    Any help would be much appreciated guys, thanks!

    D

    #207713
    Ilan Firsov
    Participant

    This is something you should do on the server side unless you don’t care that people can open the page source and see your answers.

    In any case you should use else if (and please do yourself and everyone reading your code a favor and use curly braces):

    if(answer == 'something') {
      // do something
    } else if(answer == 'something-else') {
      // do something else
    } else {
      // whatever
    }
    
    #207714
    mo_da92
    Participant

    Thanks Ilan, this is exactly what I was looking for!

    My code was correct first time but when I edited the post it changed for some reason, but I will remember for next time.

    Thanks!!

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘CSS’ is closed to new topics and replies.