www.webdeveloper.com
Results 1 to 5 of 5

Thread: Help making questionare?

  1. #1
    Join Date
    Jun 2013
    Posts
    2

    Help making questionare?

    What I would like is to have questions, and when you answer one it tells you if you were right or wrong in a popup. Then you press next question to go onto the next question. Is it possible to have your total score at the end as well? Thanks
    My script at the moment -
    HTML Code:
    <head>
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <title> - jsFiddle demo</title>
      
      <script type='text/javascript' src='http://code.jquery.com/jquery-1.8.3.js'></script>
      <link rel="stylesheet" type="text/css" href="/css/normalize.css">
      
      
      <link rel="stylesheet" type="text/css" href="/css/result-light.css">
      
      <style type='text/css'>
        
      </style>
      
    
    
    <script type='text/javascript'>//<![CDATA[ 
    $(window).load(function(){
    var questions = {
        2: 'Question 2: Is 1+1 = 2<br>' +
           '<input type="radio" name="answer" value="yes">Yes<br>' +
           '<input type="radio" name="answer" value="no">No<br>',
        3: 'Question 3: Does 4+4=8<br>' +
           '<input type="radio" name="answer" value="yes">Yes<br>' +
           '<input type="radio" name="answer" value="no">No<br>'
        };
    
    var current_question = 1;
    
    $('#questionnaire').submit(function(){
        current_question++;
        $('#questionnaire #question').html(questions[current_question]);
        return false;
    });
    });//]]>  
    
    </script>
    
    
    </head>
    <body>
      <form id="questionnaire">
      <div id="question">
          Question 1: Does 3+3=7<br>
          <input type="radio" name="answer" value="yes">Yes<br>
          <input type="radio" name="answer" value="no">No<br>
      </div>
      <input type="submit" value="Next Question" />
    </form>
      
    </body>
    
    
    

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,716
    take this as a draft:

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>Quiz</title>
    <script type='text/javascript' src='http://code.jquery.com/jquery-1.8.3.js'></script>
    <style type='text/css'>
    body{color:#000;background-color:#fff;font-family:'Bookman Old Style',Georgia,Verdana;font-size:14px;text-align:center;padding-top:250px;}
    input[type=radio]{margin-left:15px;margin-right:10px;cursor:pointer;}
    b{font-style:italic;}
    #info{position:absolute;top:10px;right:20px;display:none;border:2px solid #000;border-radius:10px;padding:50px 50px;font-size:36px;font-weight:bold;}
    #score{font-style:italic;}
    .gr{color:Green;font-weight:bold;}
    .cr{color:Crimson;font-weight:bold;}
    </style>
    <script type='text/javascript'>//<![CDATA[
    var curr=0,rights=0,wrongs=0,questions=[
    ['Does 3 + 3 = 7?','no'],
    ['Does the Earth spin?','yes'],
    ['Do cats bark?','no'],
    ['Does the Internet exist?','yes'],
    ['Is <b>webdeveloper.com</b> the best internet resource?','yes'],
    ['Is this the last question of the Quiz?','yes']
    ];
    
    function ask(){
    if(curr < questions.length){
    $('#question').html('Question '+(curr+1)+': '+questions[curr][0]);
    }
    else{
    var R=Math.round((rights/questions.length)*100),
    W=Math.round((wrongs/questions.length)*100),
    resume='not bad';
    if(W==100){resume='hopeless and pathetic stupid ass';}
    if(W>0 && W<50){resume+=', but still not excellent';}
    if(R==100){resume='genious';}
    if(R>0 && R<50){resume+=', but please quit drinking';}
    if(W==50 && R==50){resume='Rain Man';}
    document.getElementById('frm').reset();
    $('#question').empty();
    $('#frm').fadeOut('normal',function(){
    $('#score').html('The total score is: <span class="gr">'+R+'%</span> vs <span class="cr">'+W+'%</span><br /><br />According to the Quiz results You just has been considered:<br /><br /><b style="font-size:18px;">"'+resume+'"</b><h1>Congratulations!</h1>');
    });
    }
    }
    
    function inf(val){
    var bg,col;
    switch(val){case'Right':bg='#BCD379',cl='Green',rights++;break;case'Wrong':bg='#F3D326',cl='Crimson',wrongs++;break;}
    $('#info').empty().html('<span class="'+cl+'">'+val+'</span> answer!').css('background-color',bg).show(10,function(){
    $(this).fadeOut(1200,function(){
    $('#score').html('The total score is: <span class="gr">'+rights+'</span> vs <span class="cr">'+wrongs+'</span> from '+questions.length+' questions');
    curr++;document.getElementById('frm').reset();ask(curr);
    });
    });
    
    }
    
    $(window).load(function(){
    ask(curr);
    $('#score').html('The total score is: <span class="gr">'+rights+'</span> vs <span class="cr">'+wrongs+'</span> from '+questions.length+' questions');
    $('[name="answer"]').click(function(){inf(($(':checked').val()===questions[curr][1])?'Right':'Wrong');});
    });//]]>  
    </script>
    </head>
    <body>
    <div>
    <div id="info"></div>
    <div id="score"></div>
    <div id="question"></div>
    <form id="frm" action=""><input type="radio" name="answer" value="yes" />Yes<input type="radio" name="answer" value="no" />No</form>
    </div>
    </body>
    </html>
    live demo
    signature under construction

  3. #3
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,716
    *typo found.

    replace (line 49)

    Code:
    switch(val){case'Right':bg='#BCD379',cl='Green',rights++;break;case'Wrong':bg='#F3D326',cl='Crimson',wrongs++;break;}
    with

    Code:
    switch(val){case'Right':bg='#BCD379',cl='gr',rights++;break;case'Wrong':bg='#F3D326',cl='cr',wrongs++;break;}
    signature under construction

  4. #4
    Join Date
    Jun 2013
    Posts
    2
    Quote Originally Posted by Padonak View Post
    *typo found.

    replace (line 49)

    Code:
    switch(val){case'Right':bg='#BCD379',cl='Green',rights++;break;case'Wrong':bg='#F3D326',cl='Crimson',wrongs++;break;}
    with

    Code:
    switch(val){case'Right':bg='#BCD379',cl='gr',rights++;break;case'Wrong':bg='#F3D326',cl='cr',wrongs++;break;}
    Omg I love you! Works so well!
    The only problem I have now is trying to insert a picture on a question, so if I wanted to ask "is this a pig" and show a picture, how would I do that? I would know how to do it with html, but javascript baffles me. Thanks a bunch for the help

  5. #5
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,716
    Code:
    ...
    <script type='text/javascript'>//<![CDATA[
    var curr=0,rights=0,wrongs=0,questions=[
    
    ['<img src="img/pig.png" alt="" /> Is this a pig?','yes'],
    
    ['Does 3 + 3 = 7?','no'],
    ['Does the Earth spin?','yes'],
    ...
    the demo is updated. if you still can't see the image in the first question press Ctrl+R to clean the browser cache
    Last edited by Padonak; 06-28-2013 at 01:17 PM.
    signature under construction

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

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.33576 seconds
  • Memory Usage 2,892KB
  • Queries Executed 15 (?)
More Information
Template Usage (35):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (6)bbcode_code
  • (1)bbcode_html
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (5)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates