www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 21

Thread: Please, can You help me with some basic function?

  1. #1
    Join Date
    Dec 2011
    Posts
    14

    Please, can You help me with some basic function?

    Hi, I have been learning js since one week, so please don't laugh at me

    I would like to have a form on my web page which includes 4 questions.The answer for each question is "yes" or "no". There is a button below the form.
    If user answers all the questions and clicks the button, the information will be displayed in the paragraph below the form. But when user does not answer all the questions and clicks the button, the alert will show up: "Fill the form!"

    I only know how to display the paragraph with my button:

    function show_info()
    {
    var paragraph = document.getElementById('info');
    paragraph.style.display = "block";
    }

    ...but the rest (I suppose some FOR statement and IF/ELse???)
    is still difficult for me


    <body>

    <form name="smallform">
    <div><br>
    <table>
    <tr>
    <td>1</td>
    <td>First question?</td>
    <td>
    <input type="radio" name="one" value="Yes" />Yes
    </td>
    <td>
    <input type="radio" name="one" value="No" />No
    </td>
    </tr>
    <tr>
    <td>2</td>
    <td>Second question?</td>
    <td>
    <input type="radio" name="two" value="Yes" />Yes
    </td>
    <td>
    <input type="radio" name="two" value="No" />No
    </td>
    </tr>
    <tr>
    <td>3</td>
    <td>Third question?</td>
    <td>
    <input type="radio" name="three" value="Yes" />Yes
    </td>
    <td>
    <input type="radio" name="three" value="No" />No
    </td>
    </tr>
    <tr>
    <td>4</td>
    <td>Fourth question?</td>
    <td>
    <input type="radio" name="four" value="Yes" />Yes
    </td>
    <td>
    <input type="radio" name="four" value="No" />No
    </td>
    </tr>
    </table>
    </div>
    <div><br>
    <input type="button" name="diagnosis" onclick="show_info();" value="Diagnosis">
    <input type="reset" value="Clear data">
    </div>

    </form>

    <p id="info" style="display: none" name="information">Some information</p>

    </body>

    Big thanks in advance for anybody who will help me

    HAPPY NEW YEAR!

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,380

    Lightbulb One possibility

    This is one of many ways to do what you want...
    Code:
    <!DOC HTML>
    <html>
    <head>
    <title> Untitled </title>
    <script type="text/javascript">
    // From: http://www.webdeveloper.com/forum/showthread.php?t=255233
    
    function getRBtnName(GrpName) {
      var sel = document.getElementsByName(GrpName);
      var fnd = -1;
      var str = '';
      for (var i=0; i<sel.length; i++) {
        if (sel[i].checked == true) { str = sel[i].value;  fnd = i; }
      }
    //  return fnd;   // return option index of selection
    // comment out next line if option index used in line above  
      return str;
    } 
    
    function show_info() {
      var flag = true;
      if (getRBtnName('one') == '') { flag = false; }
      if (getRBtnName('two') == '') { flag = false; }
      if (getRBtnName('three') == '') { flag = false; }
      if (getRBtnName('four') == '') { flag = false; }
    
      var paragraph = document.getElementById('info');
      if (flag == true) { 
        paragraph.style.display = "none";
        return false; }  // change this to true after testing script
      else {
        paragraph.style.display = "block";
        return false;
      }
    }
    </script>
    
    </head>
    <body>
    <form name="smallform" onsubmit="return show_info()">
    <div><br>
    
    <table>
    <tr>
    <td>1</td>
    <td>First question?</td>
    <td><input type="radio" name="one" value="Yes" />Yes</td>
    <td><input type="radio" name="one" value="No" />No</td>
    </tr>
    
    <tr>
    <td>2</td>
    <td>Second question?</td>
    <td><input type="radio" name="two" value="Yes" />Yes</td>
    <td><input type="radio" name="two" value="No" />No</td>
    </tr>
    
    <tr>
    <td>3</td>
    <td>Third question?</td>
    <td><input type="radio" name="three" value="Yes" />Yes</td>
    <td><input type="radio" name="three" value="No" />No</td>
    </tr>
    
    <tr>
    <td>4</td>
    <td>Fourth question?</td>
    <td><input type="radio" name="four" value="Yes" />Yes</td>
    <td><input type="radio" name="four" value="No" />No</td>
    </tr>
    </table>
    
    </div>
    <div><br>
    <input type="button" name="diagnosis" onclick="show_info();" value="Diagnosis">
    <input type="reset" value="Clear data">
    </div>
    
    </form>
    
    <p id="info" style="display: none" name="information">
     Some information missing</p>
    
    </body>
    </html>
    BTW: You should enclose your script between [ code] and [ /code] tags
    without the spaces to make it easier to read and comment on your programs.

  3. #3
    Join Date
    Dec 2011
    Posts
    14
    Hi, I am very grateful You have written to me

    But I still have some little difficulties after testing Your script

    When the user answers at least one question in my form and clicks a button,
    the hidden paragraph is displayed. (and I want user to answer all the questions in order to see hidden paragraph). I am not fluent in English (and javascript ), so I do not know if I exactly should choose between "return fnd" or "return "str"?
    Why the value of "fnd" is "-1"? (..maybe this is obvious and I am too stupid to understand it...) Could You deconstruct this little part of the code for me?
    (I understand almost everything, except for the "fnd" variable):

    function getRBtnName(GrpName) {
    var sel = document.getElementsByName(GrpName);
    var fnd = -1;
    var str = '';
    for (var i=0; i<sel.length; i++) {
    if (sel[i].checked == true) { str = sel[i].value; fnd = i; }
    }
    // return fnd; // return option index of selection
    // comment out next line if option index used in line above
    return str;
    }

    (.......)


    THANKS A LOT FOR HELPING ME!!!!!!!

  4. #4
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,380

    Question

    Quote Originally Posted by Kovalicious View Post
    Hi, I am very grateful You have written to me

    But I still have some little difficulties after testing Your script

    When the user answers at least one question in my form and clicks a button,
    the hidden paragraph is displayed. (and I want user to answer all the questions in order to see hidden paragraph). I am not fluent in English (and javascript ), so I do not know if I exactly should choose between "return fnd" or "return "str"?
    Why the value of "fnd" is "-1"? (..maybe this is obvious and I am too stupid to understand it...) Could You deconstruct this little part of the code for me?
    (I understand almost everything, except for the "fnd" variable):

    function getRBtnName(GrpName) {
    var sel = document.getElementsByName(GrpName);
    var fnd = -1;
    var str = '';
    for (var i=0; i<sel.length; i++) {
    if (sel[i].checked == true) { str = sel[i].value; fnd = i; }
    }
    // return fnd; // return option index of selection
    // comment out next line if option index used in line above
    return str;
    }

    (.......)


    THANKS A LOT FOR HELPING ME!!!!!!!
    The part I highlighted in red makes no sense to me.
    If the user answers all the questions, then the hidden paragraph will NEVER be displayed because ALL of the questions have been answered ?????

    Is what you want to happen is that the hidden paragraph be displayed until the user has answered all the questions CORRECTLY?

    Please explain further what you really are trying to do with your hidden paragraph message.



    Concerning the radio button check function, the fnd variable is an OPTIONAL
    way of testing which radio button has been chosen. You can return the
    option number chosen if you return fnd from the function. -1 means that
    no options were chosen, 0=first option chosen, 1=second, etc.

    As it is, the str variable is returned.
    If there are no radio buttons checked, then it returns a blank string,
    otherwise it returns the value of the option chosen, in your case either 'Yes' or 'No'

    If you want it to return the value of the radio button chosen or '' if none are selected, then use this version:
    Code:
    function getRBtnName(GrpName) {
      var sel = document.getElementsByName(GrpName);
      var fnd = -1;
      var str = '';
      for (var i=0; i<sel.length; i++) {
        if (sel[i].checked == true) { str = sel[i].value;  fnd = i; }
      }
      return fnd;   // return option index of selection
    // comment out next line if option index used in line above  
    //  return str;
    } 
    
    // ..... one possible solution in the check section, depending upon your needs.
      var correct = 0;
      var ans = getRBtnName('one');
      if (ans == -1) { alert('Missing answer for 1st question'); return false; }
      else { if (ans == 'Yes') { correct++; } // or 'No' depending on correctness
                              else { return false; }
    ...

  5. #5
    Join Date
    Dec 2011
    Posts
    14
    Hi, thanks for Your patience

    I want my hidden paragraph message to be displayed only when someone answers every question. Nevermind the choice. I don't want user to see the message before answering
    ALL the questions. If user clicks the button before answering all of them, an alert should be displayed: "Answer all the questions!". I do not want user to see the message in the hidden paragraph after answering one or two questions (...or without answeriing at all). Before complete answering, the message is a secret .

    I do not know if I explain it clearly enough but maybe it is possible to modify the code You provided in order to achieve this strange aim...

    Thanks for helping!

  6. #6
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,380
    Will the hidden message change depending upon the answers given?

    If not, then this should do...
    Code:
    <!DOC HTML>
    <html>
    <head>
    <title> Untitled </title>
    <script type="text/javascript">
    // From: http://www.webdeveloper.com/forum/showthread.php?t=255233
    
    function getRBtnName(GrpName) {
      var sel = document.getElementsByName(GrpName);
      var fnd = -1;
      var str = '';
      for (var i=0; i<sel.length; i++) {
        if (sel[i].checked == true) { str = sel[i].value;  fnd = i; }
      }
    //  return fnd;   // return option index of selection
    // comment out next line if option index used in line above  
      return str;
    } 
    
    function show_info() {
      var flag = true;
      if (getRBtnName('one') == '') { flag = false; }
      if (getRBtnName('two') == '') { flag = false; }
      if (getRBtnName('three') == '') { flag = false; }
      if (getRBtnName('four') == '') { flag = false; }
    
      var paragraph = document.getElementById('info');
      if (flag == false) { 
        alert('You must answer all the questions!!!');
        paragraph.style.display = "none";
        return false; }  // change this to true after testing script
      else {
        paragraph.style.display = "block";
        return false;
      }
    }
    </script>
    
    </head>
    <body>
    <form name="smallform" onsubmit="return show_info()">
    <div><br>
    
    <table>
    <tr>
    <td>1</td>
    <td>First question?</td>
    <td><input type="radio" name="one" value="Yes" />Yes</td>
    <td><input type="radio" name="one" value="No" />No</td>
    </tr>
    
    <tr>
    <td>2</td>
    <td>Second question?</td>
    <td><input type="radio" name="two" value="Yes" />Yes</td>
    <td><input type="radio" name="two" value="No" />No</td>
    </tr>
    
    <tr>
    <td>3</td>
    <td>Third question?</td>
    <td><input type="radio" name="three" value="Yes" />Yes</td>
    <td><input type="radio" name="three" value="No" />No</td>
    </tr>
    
    <tr>
    <td>4</td>
    <td>Fourth question?</td>
    <td><input type="radio" name="four" value="Yes" />Yes</td>
    <td><input type="radio" name="four" value="No" />No</td>
    </tr>
    </table>
    
    </div>
    <div><br>
    <input type="button" name="diagnosis" onclick="show_info();" value="Diagnosis">
    <input type="reset" value="Clear data"
     onclick="document.getElementById('info').style.display='none'">
    </div>
    
    </form>
    
    <p id="info" style="display:none;background-Color:red;color:white;width:200px;font-size:2em">
    Here is your reward for answering all the questions!
    </p>
    
    </body>
    </html>
    Last edited by JMRKER; 12-31-2011 at 06:39 PM.

  7. #7
    Join Date
    Dec 2011
    Posts
    14
    YES, IT WORKS!

    I was very close to this but it looks like I need to work again on the format of basic functions.

    Actually in that particular case it doesn't matter what the answers are. The important issue is that user should fill the form. But, of course, I also thought about changing the hidden message depending upon the answers given... Let's say I have two different hidden messages... Certainly, I will need to have two paragraphs with id's, then I assume I should adapt to my needs the code which You provided in Your second reply and connect it with some if/else statements...

    <code>
    var correct = 0;
    var ans = getRBtnName('one');
    if (ans == -1) { alert('Missing answer for 1st question'); return false; }
    else { if (ans == 'Yes') { correct++; } // or 'No' depending on correctness
    else { return false; }
    </code>

    so if You have free time...

    But I don't want to bother You too much...

    One more time: THANK YOU VERY MUCH!!!

  8. #8
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,380

    Lightbulb Something to try ...

    Modify this to your heart's content.
    Code:
    <!DOC HTML>
    <html>
    <head>
    <title> Untitled </title>
    <script type="text/javascript">
    // From: http://www.webdeveloper.com/forum/showthread.php?t=255233
    
    function getRBtnName(GrpName) {
      var sel = document.getElementsByName(GrpName);
      var fnd = -1;
      var str = '';
      for (var i=0; i<sel.length; i++) {
        if (sel[i].checked == true) { str = sel[i].value;  fnd = i; }
      }
    //  return fnd;   // return option index of selection
    // comment out next line if option index used in line above  
      return str;
    } 
    
    function show_info() {
      var ques = '0';
      var flag = true;
    
    // condition for WRONG answers
      var tmp = getRBtnName('one');
      if (tmp == '') { flag = false; }  if (tmp == 'No') { ques = "1"; }
          tmp = getRBtnName('two');
      if (tmp == '') { flag = false; }  if (tmp == 'Yes') { ques = "2"; }
          tmp = getRBtnName('three');
      if (tmp == '') { flag = false; }  if (tmp == 'No') { ques = "3"; }
          tmp = getRBtnName('four');
      if (tmp == '') { flag = false; }  if (tmp == 'Yes') { ques = "4"; }
    
      var paragraph = document.getElementById('info');
      if (flag == false) { 
        alert('You must answer all the questions!!!');
        paragraph.style.display = "none";
        return false;   // change this to true after testing script
      } else {
        switch (ques) {
          case '1' : tmp = 'Missed question #'+ques; break;
          case '2' : tmp = 'Missed question #'+ques; break;
          case '3' : tmp = 'Missed question #'+ques; break;
          case '4' : tmp = 'Missed question #'+ques; break;
           default : tmp = 'Here is your reward for answering all the questions correctly!'; break;
        }
        document.getElementById('info').innerHTML = tmp;
        paragraph.style.display = "block";
        return false;
      }
    }
    </script>
    
    </head>
    <body>
    <form name="smallform" onsubmit="return show_info()">
    <div><br>
    
    <table>
    <tr>
    <td>1</td>
    <td>First question?</td>
    <td><input type="radio" name="one" value="Yes" />Yes</td>
    <td><input type="radio" name="one" value="No" />No</td>
    </tr>
    
    <tr>
    <td>2</td>
    <td>Second question?</td>
    <td><input type="radio" name="two" value="Yes" />Yes</td>
    <td><input type="radio" name="two" value="No" />No</td>
    </tr>
    
    <tr>
    <td>3</td>
    <td>Third question?</td>
    <td><input type="radio" name="three" value="Yes" />Yes</td>
    <td><input type="radio" name="three" value="No" />No</td>
    </tr>
    
    <tr>
    <td>4</td>
    <td>Fourth question?</td>
    <td><input type="radio" name="four" value="Yes" />Yes</td>
    <td><input type="radio" name="four" value="No" />No</td>
    </tr>
    </table>
    
    </div>
    <div><br>
    <input type="button" name="diagnosis" onclick="show_info();" value="Diagnosis">
    <input type="reset" value="Clear data"
     onclick="document.getElementById('info').style.display='none'">
    </div>
    
    </form>
    
    <p id="info"
     style="display:none;background-Color:red;color:white;width:200px;font-size:2em"></p>
    
    </body>
    </html>

  9. #9
    Join Date
    Dec 2011
    Posts
    14
    Thanks a lot!

    I am very grateful!!!

    I hope I will soon delve deeper in the matter of JavaScript
    by analysing the scripts You provided...


  10. #10
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,380

    Thumbs up

    Quote Originally Posted by Kovalicious View Post
    Thanks a lot!

    I am very grateful!!!

    I hope I will soon delve deeper in the matter of JavaScript
    by analysing the scripts You provided...

    You're most welcome.
    Happy to help.
    Happy New Year!

  11. #11
    Join Date
    Dec 2011
    Posts
    14
    Hi, my favourite Master!

    ...and what if I have the same kind of form as the example above (the one that user should complete to see hidden message) - but instead of radio buttons, I have a list of five options for each of three question??????????????

    Can You deconstruct the differences in creating the scripts for my simple forms: 1.with "radio buttons" and 2. with "options"? It is very difficult for me to learn on my own.

    <code><form action="" onsubmit="return help_me()" name="smallform">
    <div>
    <table>
    <tr>
    <td>1</td>
    <td>First question?</td>
    <td>
    <select id="sel1">
    <option value="opt1" name="one" disabled="disabled" selected="selected">Choose something</option>
    <option value="opt2" name="one">first</option>
    <option value="opt3" name="one">second(1pkt)</option>
    <option value="opt4" name="one">third</option>
    <option value="opt5" name="one">fourth</option>
    <option value="opt6" name="one">fifth</option>
    </select>
    </td>
    </tr>
    <tr>
    <td>2</td>
    <td>sceond question</td>
    <td>
    <select id="sel2">
    <option value="opt1" name="two" disabled="disabled" selected="selected">Choose something</option>
    <option value="opt2" name="two">first</option>
    <option value="opt3" name="two">sec(1pkt)</option>
    <option value="opt4" name="two">thir(2pkt)</option>
    <option value="opt5" name="two">fiv(3pkt)</option>
    <option value="opt6" name="two">s</option>
    </select>
    </td>
    </tr>
    <tr>
    <td>3</td>
    <td>Third question</td>
    <td>
    <select id="sel3">
    <option value="opt1" name="three" disabled="disabled" selected="selected">Choose something</option>
    <option value="opt2" name="three">f</option>
    <option value="opt3" name="three">s</option>
    <option value="opt4" name="three>t</option>
    <option value="opt5" name="three">fi</option>
    <option value="opt6" name="three">s</option>
    </select>
    </td>
    </table>
    </div>
    <div>
    <input type="button" onclick="help_me_with_this_function();">
    <input type="reset" value="clear data">
    </div>
    </form>
    <p id="diagnoza" style="display: none">What is written and hidden here, should be displayed after user answers all the questions.
    </p></code>

    Thanks for helping

  12. #12
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,380

    Lightbulb Something to try ...

    It might go a bit faster if I understood what it is that you are trying to accomplish,
    but as far as I can tell, this script should do what you want.

    (There were a few typos you left in as well.
    Always check your error console for errors and try to fix them before submitting questions.)

    Code:
    <!DOC HTML>
    <html>
    <head>
    <title> Untitled </title>
    <script type="text/javascript">
    function help_me() {
      var ques = '0';
      var flag = true;
    
    // condition for WRONG answers
      var tmp = document.getElementById('sel1').value;
      if (tmp == '') { flag = false; }  if (tmp != 'opt1') { ques = "1"; }
          tmp = document.getElementById('sel2').value;
      if (tmp == '') { flag = false; }  if (tmp != 'opt3') { ques = "2"; }
          tmp = document.getElementById('sel3').value;
      if (tmp == '') { flag = false; }  if (tmp != 'opt5') { ques = "3"; }
    
      var paragraph = document.getElementById('diagnoza');
      if (flag == false) { 
        alert('You must answer all the questions!!!');
        paragraph.style.display = "none";
        return false;   // change this to true after testing script
      } else {
        switch (ques) {
          case '1' : tmp = 'Missed question #'+ques; break;
          case '2' : tmp = 'Missed question #'+ques; break;
          case '3' : tmp = 'Missed question #'+ques; break;
           default : tmp = 'Here is your reward for answering all the questions correctly!'; break;
        }
        document.getElementById('diagnoza').innerHTML = tmp;
        paragraph.style.display = "block";
        return false;
      }
    }
    </script>
    
    </head>
    <body>
    <form action="" onsubmit="return help_me()" name="smallform">
    <div>
    <table>
    <tr>
    <td>1</td>
    <td>First question?</td>
    <td>
    <select id="sel1">
    <option value="" name="one" disabled="disabled" selected="selected">Choose something</option>
    <option value="opt1" name="one">first</option>
    <option value="opt2" name="one">second(1pkt)</option>
    <option value="opt3" name="one">third</option>
    <option value="opt4" name="one">fourth</option>
    <option value="opt5" name="one">fifth</option>
    </select>
    </td>
    </tr>
    <tr>
    <td>2</td>
    <td>sceond question</td>
    <td>
    <select id="sel2">
    <option value="" name="two" disabled="disabled" selected="selected">Choose something</option>
    <option value="opt1" name="two">first</option>
    <option value="opt2" name="two">sec(1pkt)</option>
    <option value="opt3" name="two">thir(2pkt)</option>
    <option value="opt4" name="two">fiv(3pkt)</option>
    <option value="opt5" name="two">s</option>
    </select>
    </td>
    </tr>
    <tr>
    <td>3</td>
    <td>Third question</td>
    <td>
    <select id="sel3">
    <option value="" name="three" disabled="disabled" selected="selected">Choose something</option>
    <option value="opt1" name="three">f</option>
    <option value="opt2" name="three">s</option>
    <option value="opt3" name="three">t</option>
    <option value="opt4" name="three">fi</option>
    <option value="opt5" name="three">s</option>
    </select>
    </td>
    </table>
    </div>
    <div>
    <input type="button" value="Check Answers" onclick="help_me();">
    <input type="reset" value="clear data">
    </div>
    </form>
    <p id="diagnoza" style="display: none">
    What is written and hidden here, should be displayed after user answers all the questions.
    </p>
    </body>
    </html>
    Why you would want to do it is a mystery to me.

    BTW: You should enclose your code between [ code] and [ /code] tags (without the spaces)
    not the <code> tag you tried in your last attempt.

  13. #13
    Join Date
    Dec 2011
    Posts
    14
    Thanks again for helping me - once again

    I hope I am not so strange and mysterious as You think. I am just going to become an addiction therapist, so as an excercise I try to create some interactive tests which tell the user if he/she is addicted to alcohol

    There are many tests researching this problem. Some of them are basic (I only want the user to answer. - No matter what the answers are. - Info displayed after answering is the same), others - more complicated... For example the code for those more complicated should display (only after the user will answer all the questions!!!) different info (diagnosis) depending upon the option made for each question.

    ...so there is a long way ahead and I hope I will be able to accomplish that on my own soon.

    For now, I am happy because I have managed to modify (actually I've only made some simplification) Your last code and it works! -
    I just wanted the user to complete that form - no matter the option made. The most important thing was not to show hidden info without answering (no matter the choice!!!!!!!) Look at this, please:

    Code:
    function help_me() {
    var flag = true;
    // condition for not chosen any option 
     var tmp = document.getElementById('sel1').value;
     if (tmp == '') { flag = false; }
         tmp = document.getElementById('sel2').value;
     if (tmp == '') { flag = false; }
         tmp = document.getElementById('sel3').value;
     if (tmp == '') { flag = false; }
    
     var paragraph = document.getElementById('diagnoza');
    
    if (flag == false) {
        alert ("Answer all the questions! - No matter what the choice!");
        paragraph.style.display = "none";
        return true; }
      else {
        paragraph.style.display = "block";
        return false;
      }
    }
    It shows information from the hidden paragraph... What do You think about it? Would You write it in more simple way? Do You see some mistakes?

    Of course Your code is very helpful.
    Thanks to You, the things started getting more simple

  14. #14
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,380
    Looks fine to me so long as it accomplishes your task and solves your problems.

    It looks like the only thing you removed is the ability to check for a correct answer.
    If it is not needed to be checked, then your solution should work fine.

    Could it be simplified further, possibly. But if you understand it and can modify it
    without creating additional errors or problem, then you should apply the KISS principle.
    Or it's corrollary: if ain't broke, don't fix it!

    The nice thing about designing your own programs is that you can change as needed.
    Keep of the good work.
    Good Luck!

  15. #15
    Join Date
    Dec 2011
    Posts
    14
    Hi! It's me again...

    I've been thinking about the function help_me() from my previous reply... - What if I have much bigger amount of 'select' elements??? - ...so I modified Your script further in order to not get each 'select' element by 'id'...

    Code:
    function help_me() {
    var tmp = document.getElementsByTagName('select');
    var paragraph = document.getElementById('diagnoza');
    for (var i=0; i<tmp.length;i++) {
        if (tmp[i].value == '') {
           alert ("Answer all the questions! - No matter what the choice!");
           paragraph.style.display = "none";
           return false; }
        else {
             paragraph.style.display = "block";
             return true; } } }
    But with the code above the user doesn't have to answer all the questions to see the secret/reward message in the hidden paragraph. Here it is possible to see it, if You answer the first one(because 'i = 0') or the second one(if 'i=1') or the third (if 'i=2'), etc.

    Where is my mistake?

    What should I do to accomplish my little task (the user should answer all the questions to see the message, but there are many questions and I don't want to reference them by 'id') ???

    Thanks for help

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles