Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Questionnaire Help

    Hi Guys,
    I wonder if anyone could help me? I am making a retail site and I need to make some sort of questionnaire to direct customers to the correct type of product.
    I have five multiple choice questions and I want to assign a value to each answer, total it all at the end and show a few products that would suit... I'm quite new to JS and I don't know if this is even possible.
    To make it slightly more confusing I would like question two to only be shown if a certain answer is given to question one.
    I would really appreciate some help.
    Thank you
    Jessica.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,907
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    This forum is not a free coding service. As a general rule, the people helping out in this forum don't write code for others (especially code that appears to be for a commercial application), but try to help with fixing code that doesn't work. You may perhaps get someone to write this script for you, but you'll be far more likely to get help if you have made a substantial effort and written some code yourself. Then someone here will almost certainly help you correct/improve your work.


    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I wasn't asking for anyone to code for me, I want to know if this is possible and to maybe point me in the right direction... I have spent a good few hours on it and I didn't want to waste anymore time if it’s something that is never going to work.

    Thanks anyway...

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,907
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Of course it is possible, (but perhaps not achieveable for you at this stage if you don't have much knowledge of Javascript) but your requirement is too vague and ill-defined to do much with. What does "some sort of questionaire" mean?

    Here is code to add up the scores of sets of radio buttons:-

    Code:
    <html>
    <head>
    <body>
    
    <form name= "myform">
    Choose one from this group<br>
    RED <input type = "radio" name = "rad1" value = "0" >
    BLUE <input type = "radio" name = "rad1" value = "1" >
    GREEN  <input type = "radio" name = "rad1" value = "2" >
    YELLOW <input type = "radio" name = "rad1" value = "3">
    BROWN <input type = "radio" name = "rad1" value = "4">
    <br>
    And one from this group<br>
    PINK<input type = "radio" name = "rad2" value = "0" >
    PURPLE<input type = "radio" name = "rad2" value = "1" >
    GREY<input type = "radio" name = "rad2" value = "2" >
    BLACK<input type = "radio" name = "rad2" value = "3" >
    WHITE <input type = "radio" name = "rad2" value = "4">
    
    <br><br>
    
    <input type = "button" value = "Calculate Score" onclick ="calc()">
    </form>
    
    <script type = "text/javascript">
    
    var numOfGroups = 2;
    
    function calc() {
    
    var score = 0;
    
    for (var j =1; j<=numOfGroups; j++) {
    var f = document["myform"]["rad"+j];
    for (var i=0; i<f.length; i++) {
    if (f[i].checked) {
    score += Number(f[i].value);
    }
    }
    }
    alert ("You scored "  + score);
    
    }
    </script>
    
    </body>
    </html>
    Is that the sort of thing you want?

    Have you thought this through? Suppose a user scores 1 + 5 + 14 total 20, that is the same result total as scores of 14 + 1 + 5 - very different answers.

    Why not simply use a select box where the user can choose the type of product he is interested in?

    As this is a commercial site I suggest you do what you would expect to do in any other field when you wanted technical expertise - hire a professional.
    Last edited by Philip M; 07-24-2012 at 04:03 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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