Help with Poll-like webpage.

Discussion in 'Computer Science & Culture' started by ScrollMaker, Apr 23, 2004.

Thread Status:
Not open for further replies.
  1. ScrollMaker I Make Scrolls Registered Senior Member

    Messages:
    177
    I need to make a website that is sort of like a multiple choice test. What I have is a page with an iFrame in the middle for the page with the question. What I need the webpage to do is have 4 radio-buttons and then a submit button. After the submit button is pressed, a variable will be incremented if they chose the right radio-button. Also when the submit button is pressed a new question will appear. At the end I need the tallied up amount of correct answers. I have been trying to do this but cannot figure out how to get radio buttons to work properly (and other things). Help and suggestions please!

    Please Register or Log in to view the hidden image!

     
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. Stryder Keeper of "good" ideas. Valued Senior Member

    Messages:
    13,105
    I've generated a rather crumby example. (Crumby because it's messy and probably illegable.)

    anyway it should give you something to look at Http://www.chatsoba.com/tutorial/q.html

    Before I explain about what I created for reference purposes, you should note that Javascript can't save things to a file unless it calls to a CGI script like Perl, or instead of using Javascript PHP is used.

    In most cases with Polls, they aren't very useful unless you can save the result, so it's not like you could generate a Vote poll where users see how many votes have tallied through other people voting, However Javascript can do those neat little questionaires that carry numeric values and tally the number at the end (which is what my examples about).

    I use a few different methods to do things within the script and the script itself will seem haphazard, since I haven't cleaned it up to be ergonomic. (namely small and efficient for interpreters)

    I haven't covered any area's of autheniticating that data is met correctly with the answers that are needed (ergo an alert box exists as a simple method.)

    The whole questionaire (without any real questions) was written to exist in one HTML page, and generate the appearance of multiple pages in an IFRAME.

    In my example I didn't follow what you were after, but you should get an idea of how to create the incrementation. Note that eval() is a useful function to make sure that your Variables are mathematically applied rather than afixed to one another.
    (namely)
    if a = "1" and b = "2".
    a+b should equal "3" when using eval. otherwise obscurely it might equal "12".

    You'll also notice in my example I use ONCLICK to decide that the radio has been clicked, rather than select something to check it, then evaluate that it's checked to output a value.

    (The NOTE here is that I created a temporary storing variable for the value, that is added to a true Total/Counter, however the temporary variable is always zerod before being used, so that people can switch their choice before clicking a next button)

    hope the example helps.
     
  4. Google AdSense Guest Advertisement



    to hide all adverts.
  5. Kunax Sciforums:Reality not required Registered Senior Member

    Messages:
    2,385
    yea, got 18, is that good

    Please Register or Log in to view the hidden image!



    edit: did you make it yourself, lots of infotext in there
     
  6. Google AdSense Guest Advertisement



    to hide all adverts.
  7. ScrollMaker I Make Scrolls Registered Senior Member

    Messages:
    177
    Thanks for the helpful webpage! Only thing is, is that after I select an image from the radio-buttons the screen goes blank. I don't believe my browser is showing it correctly.
     
  8. ScrollMaker I Make Scrolls Registered Senior Member

    Messages:
    177
    Nevermind, just wasn't working under things besides IE. I'm getting closer to my goal

    Please Register or Log in to view the hidden image!

    I forgot to mention that there will be five players and so the first question is for the first player, second for second, etc. So I'm going to need five different totals *_* . I'll see if I can get something working, but some tips would be nice. Thanks a lot

    Please Register or Log in to view the hidden image!

     
  9. Stryder Keeper of "good" ideas. Valued Senior Member

    Messages:
    13,105
    Well thats something I didn't mention, perhaps I took for granted if you wanted to make the Javascript compatible with different browsers you would have to write some code to Identify the browser so that you could then work out the best way of scripting the code that would be necessary to generate the effect your after.

    Also the whole usage of Javascript means that if someone uses a browser with strict rulesets, their is a possibility that it wont supply the correct Javascript formatting.

    As for Five people, it's possible to rig something like that for one browser, however if you were wanting it to work for five people on five different machines you would have the same problem I mentioned previously where you would need access to a CGI script or PHP.
    I would suggest in that instance a DB file method of storing the information since you would really only be storing pair variables (User = Total), it is possible to use a SQL database (like mySQL) but for the limited amount of information it's hardly worth connecting to an outside or internal database and doing all the authentication, opening, reading, writing, closing of a database just to perform something that could be done quicker with a DB file. (Thats why Counter scripts tend to use DB files rather than SQL Databases and why Forums packages use SQL databases rather than DB files)

    Kunax,
    Yes I did write the script, I learnt a few bits and pieces when younger and had a few examples I pull from that I wrote previously that I use instead of memory for doing things.

    A good JS tutorial I learned from back in the day was "Voodoo's Javascript Tutorial", and I printed out back then the entire HTML/JAVASCRIPT (1.0) convention that was housed at Netscape at the time. (About 300pgs)

    the usage of split() actually came from cookie scripting, however since scripting cookies is hardly used nowadays, some of how the scripting was done can still be used elsewhere.
     
  10. ScrollMaker I Make Scrolls Registered Senior Member

    Messages:
    177
    This project is going to be used only once on one computer that will be using IE. It's a project for class so compatibility isn't an issue. I'll show you what I've done so far in about an hour or two.
     
  11. ScrollMaker I Make Scrolls Registered Senior Member

    Messages:
    177
  12. Stryder Keeper of "good" ideas. Valued Senior Member

    Messages:
    13,105
    Actually I spotted an error I dropped in my code I should of debugged, In the WTL() function. Simply the addition of Break; is enough to cause it to "break" the current code cycle in the instance of the alert and not move to the next question.

    simple fix:
    Code:
    function WTL(){
    if(HV=="0"){
    alert("You need to select an answer.");
    Break;
    } 
    Qm=eval(Qm+1);
    TTL=eval(TTL+HV);
    QFrame.document.close();
    HV="0";
    AskQ(Qm);
    }
    
    The restart button code is slightly errored look for "Reloader" were it should be "ReLoader".

    I'm not 100% sure whats causing the lack Buttons on a form when you get to the next question on yours, so it might be some very small alteration.
    (Remember when adding strings for questions etc, don't use "~" or "#" and one other point to remember is if you use a " or ' within a string that has either of those at both ends ['like' "this"] you should include a "\" infront of it.
    "string\'s like this " or 'string\'s like this'.
    You have to do that or the interpreter gets a little lost in translation.)
     
    Last edited: Apr 24, 2004
  13. ScrollMaker I Make Scrolls Registered Senior Member

    Messages:
    177
    What do you mean the lack of buttons? I removed the restart button if that's what you are referring to.
     
  14. Stryder Keeper of "good" ideas. Valued Senior Member

    Messages:
    13,105
    I spotted something else that would probably help (It's always afterwards when you start to debug and processing what you create differently that you start fixing things)

    in the AskQ(Qnum) function, goto the following instance:
    Code:
    Q=Qstring[Qnum].split("~");
    
    And insert this after it.:
    Code:
    QFrame.document.open();
    
    Also in the same function goto:

    Code:
    }
    }
    
    and alter it to be like below:
    Code:
    }
    QFrame.document.close();
    }
    
    This will stop the pages original problem of being "Open" in the sense that the browser will continue to wait for more information to be parsed to it. (Imagine that if someone could insert code into your open ended session you might get a "Knock knock Neo" on the screen)

    As for the problem I mentioned, your going to have to assign a pixel value to the IFRAME rather than "100%", for some reason when it gets populated by the next question it robs the box of the "NEXT" button, meaning you can't go any further.

    (I did some alterations to your version to get it to work, thats how I got these answers.)

    My version Updated will be available short:
    Http://www.chatsoba.com/tutorial/q.html
     
    Last edited: Apr 24, 2004
  15. ScrollMaker I Make Scrolls Registered Senior Member

    Messages:
    177
    I updated the page with the things you suggested. I assume I wasn't having the problem you were having...
     
  16. Stryder Keeper of "good" ideas. Valued Senior Member

    Messages:
    13,105
    It's working perfectly now, at least in IE, although tests with other browsers would be the next thing to do, but as you mentioned you aren't worried about that.
     
  17. ScrollMaker I Make Scrolls Registered Senior Member

    Messages:
    177
    I tried to implement the five team scoring system but ran into a problem. I can't figure it out, but everytime team one gets a score of 5 and everyone else gets 0. Check out http://www.exodus-news.net/dan/fake2.php for the source code.
     
  18. Stryder Keeper of "good" ideas. Valued Senior Member

    Messages:
    13,105
    Okay what I've done is I've left my original version alone this time, since it's got all the notes in it, and generated a new version that covers the whole problem.

    Http://www.chatsoba.com/tutorial/qteam.html

    A few alterations, one minor change to make a team array hold the values, and some other changes that use For Loops to lessen the coding further.
     
  19. ScrollMaker I Make Scrolls Registered Senior Member

    Messages:
    177
    Awesome job Stryderuknown! My attempted code was pretty darn similar to that

    Please Register or Log in to view the hidden image!

    Thanks for a whole thread of help.
     
Thread Status:
Not open for further replies.

Share This Page