/    Sign up×
Community /Pin to ProfileBookmark

Javascript Point system quiz – genius help needed

I need help with this quiz I have it working and everything but I want the points to be calculated up when you press submit and go to the results page. so I guess the question is (I read the sticky) How do I calculate the exact score with the certain javascript that I am using?

I have a zip file for you to download the files in. All the javascript is embedded into the main quiz with the questions and such. And the other pages are just result pages.

[url]http://www.gregmaustin.com/uhcl/Student_Quiz.zip[/url]

to post a comment
JavaScript

14 Comments(s)

Copy linkTweet thisAlerts:
@gregmaustinauthorFeb 05.2010 — I figured if I explained myself better I may get an actual answer. Right now I have the code going to a seperate .html document which tallies the scores from 0-30 goes to one page... 31-60 goes to another pages and 61-90 goes to different page.

What I am trying to do is get the actual score that they made to go to the next page. I suppose using cookies or something. Javascript is not my strong point so if anybody could give me the littliest of hint to get this done that would be great.

[CODE]
<script language="JavaScript" type="text/javascript">
<!--Hide JavaScript from Java-Impaired Browsers
function test_it(entry) {
if (entry.value!=null && entry.value.length!=0) {
entry.value=""+ eval(entry.value);
}
computeForm(entry.form);
}
function computeForm(form) {
var total=0

for (var count=0; count<4; count++)
{
if (form.a[count].checked){
var total=total+parseInt(form.a[count].value);
}
}

for (var count=0; count<4; count++)
{
if (form.b[count].checked){
var total=total+parseInt(form.b[count].value);
}
}

for (var count=0; count<4; count++)
{
if (form.c[count].checked){
var total=total+parseInt(form.c[count].value);
}
}

for (var count=0; count<4; count++)
{
if (form.d[count].checked){
var total=total+parseInt(form.d[count].value);
}
}

for (var count=0; count<4; count++)
{
if (form.e[count].checked){
var total=total+parseInt(form.e[count].value);
}
}

for (var count=0; count<4; count++)
{
if (form.f[count].checked){
var total=total+parseInt(form.f[count].value);
}
}

for (var count=0; count<4; count++)
{
if (form.g[count].checked){
var total=total+parseInt(form.g[count].value);
}
}

for (var count=0; count<4; count++)
{
if (form.h[count].checked){
var total=total+parseInt(form.h[count].value);
}
}

for (var count=0; count<4; count++)
{
if (form.i[count].checked){
var total=total+parseInt(form.i[count].value);
}
}

for (var count=0; count<4; count++)
{
if (form.j[count].checked){
var total=total+parseInt(form.j[count].value);
}
}

for (var count=0; count<4; count++)
{
if (form.k[count].checked){
var total=total+parseInt(form.k[count].value);
}
}

for (var count=0; count<4; count++)
{
if (form.l[count].checked){
var total=total+parseInt(form.l[count].value);
}
}

for (var count=0; count<4; count++)
{
if (form.m[count].checked){
var total=total+parseInt(form.m[count].value);
}
}

for (var count=0; count<4; count++)
{
if (form.n[count].checked){
var total=total+parseInt(form.n[count].value);
}
}

for (var count=0; count<4; count++)
{
if (form.o[count].checked){
var total=total+parseInt(form.o[count].value);
}
}

for (var count=0; count<4; count++)
{
if (form.p[count].checked){
var total=total+parseInt(form.p[count].value);
}
}

for (var count=0; count<4; count++)
{
if (form.q[count].checked){
var total=total+parseInt(form.q[count].value);
}
}

for (var count=0; count<4; count++)
{
if (form.r[count].checked){
var total=total+parseInt(form.r[count].value);
}
}

for (var count=0; count<4; count++)
{
if (form.s[count].checked){
var total=total+parseInt(form.s[count].value);
}
}

for (var count=0; count<4; count++)
{
if (form.t[count].checked){
var total=total+parseInt(form.t[count].value);
}
}

for (var count=0; count<4; count++)
{
if (form.u[count].checked){
var total=total+parseInt(form.u[count].value);
}
}

for (var count=0; count<4; count++)
{
if (form.v[count].checked){
var total=total+parseInt(form.v[count].value);
}
}

for (var count=0; count<4; count++)
{
if (form.w[count].checked){
var total=total+parseInt(form.w[count].value);
}
}

for (var count=0; count<4; count++)
{
if (form.x[count].checked){
var total=total+parseInt(form.x[count].value);
}
}


for (var count=0; count<4; count++)
{
if (form.y[count].checked){
var total=total+parseInt(form.y[count].value);
}
}

for (var count=0; count<4; count++)
{
if (form.z[count].checked){
var total=total+parseInt(form.z[count].value);
}
}

for (var count=0; count<4; count++)
{
if (form.aa[count].checked){
var total=total+parseInt(form.aa[count].value);
}
}

for (var count=0; count<4; count++)
{
if (form.bb[count].checked){
var total=total+parseInt(form.bb[count].value);
}
}

for (var count=0; count<4; count++)
{
if (form.cc[count].checked){
var total=total+parseInt(form.cc[count].value);
}
}



if (total<0){window.location="results1.html" }
else if (total<30){window.location="results2.html" }
else if (total<60){window.location="results3.html" }
else if (total<90){window.location="results4.html" }
else {window.location="results5.html" }
}
//-->
</script>
[/CODE]
Copy linkTweet thisAlerts:
@harrierdhFeb 05.2010 — May be you're not getting an answer because nobody wants to download a possible malicious zip file. Read the guidelines. Post all your code or a link to your page. I also have a pet peeve about coders that don't indent their code. But don't get me going.

In any event, you could concatenate your score to the query string.

var url = "results2.html" + "?" + total;

window.location=url;

Then in results2.html

var url = location.href;

url = url.toString();

var urlArray = url.split("?");

var total = urlArray[1];

alert(total);
Copy linkTweet thisAlerts:
@gregmaustinauthorFeb 05.2010 — Apologize for all that and thank you for your help.

what would I use to show the score on the html page?

Here is the link...

http://www.gregmaustin.com/uhcl/survey/LearningSurvey.html

Once you hit submit it, they all go to results2.html until I get the score figured out.

http://www.gregmaustin.com/uhcl/survey/results2.html When you load it, theit comes up with a error that says "undefined."
Copy linkTweet thisAlerts:
@harrierdhFeb 05.2010 — Run the code in a function so the variables are protected.

[CODE]
<head>
<script>
function checkTotal() {
var url = location.href;
url = url.toString();
var urlArray = url.split("?");
var total = urlArray[1];
document.getElementById("screentotal").innerHTML= total;
}
window.onload = checkTotal; // run the script after the html is loaded
</script>
</head>
<body>
<p id="screentotal"></p>
</body>
[/CODE]


You could use just about any tag to replace the <p> for instance a <div> would work too.

Also check out the icons above your reply. Hover over them. The # lets you insert code and retain your formatting. It also makes it easier for cutting and pasting.

Hope this helps.
Copy linkTweet thisAlerts:
@gregmaustinauthorFeb 05.2010 — Thank you sir you've been a huge help. It's almost there I know it! I am pretty sure I have to define the score using the checkTotal variable. But I am not sure how to do that on the LearningSurvey.html

I inserted the code for results2.html... which is:

[CODE]
<script>
function checkTotal() {
var url = location.href;
url = url.toString();
var urlArray = url.split("?");
var total = urlArray[1];
document.getElementById("screentotal").innerHTML= total;
}
window.onload = checkTotal; // run the script after the html is loaded
</script>

[/CODE]


So I am just thinking that I am missing something on LearningSurvey.html ? What would that be?
Copy linkTweet thisAlerts:
@harrierdhFeb 05.2010 — I suspect the problem is your form tag. Try using method="get" in your form tag. I think it's defaulting to method="post".

For that matter I don't see why you even need the form tag. It looks like it would work without it.

If you are still having problems, put an alert in results.html just after

var url = location.href;

alert(url);
Copy linkTweet thisAlerts:
@gregmaustinauthorFeb 05.2010 — would I put

[CODE]<script>
function checkTotal() {
var url = location.href;
url = url.toString();
var urlArray = url.split("?");
var total = urlArray[1];
document.getElementById("screentotal").innerHTML= total;
}
window.onload = checkTotal; // run the script after the html is loaded
</script>[/CODE]


in LearningSurvey.html and results2.html?
Copy linkTweet thisAlerts:
@harrierdhFeb 05.2010 — No just in results2.html. I'm pretty sure about the form tag problem in LearningSurvey.html. The rest of that code looks ok.

After you click the button and go to the results2.html, you can look at the top of your browser and see the string formatted. It should say.

http://www.gregmaustin.com/uhcl/survey/results2.html?30

right now it says

http://www.gregmaustin.com/uhcl/survey/results2.html
Copy linkTweet thisAlerts:
@gregmaustinauthorFeb 05.2010 — How does the LearningSurvey.html know to calculate the score and send it to results2.html I feel like I am missing something on LearningSurvey.html
Copy linkTweet thisAlerts:
@harrierdhFeb 05.2010 — You have some problems. First the url creation is outside the function because of a misplaced squirly bracket.

if (total<0){window.location="results1.html" }

else if (total<30){window.location="results2.html" }

else if (total<60){window.location="results2.html" }

else if (total<90){window.location="results2.html" }

else {window.location="results4.html" }

}

var url = "results2.html" + "?" + total;
window.location=url;

var url = "results2.html" + "?" + total;
window.location=url;

var url = "results2.html" + "?" + total;
window.location=url;

var url = "results2.html" + "?" + total;
window.location=url;


Should be

if (total<0){window.location="results1.html" }

else if (total<30){window.location="results2.html" }

else if (total<60){window.location="results2.html" }

else if (total<90){window.location="results2.html" }

else {window.location="results4.html" }

var url = "results2.html" + "?" + total;
window.location=url;

var url = "results2.html" + "?" + total;
window.location=url;

var url = "results2.html" + "?" + total;
window.location=url;

var url = "results2.html" + "?" + total;
window.location=url;

}

Second, you are declaring total an url multiple times;

You already declared total once at the top of the function. Remove all the var's inside your if statements. Every time you do that you are keeping it out of scope when you build your url's. That makes it a private variable.

I get an error in Companion.js (a debugger for IE).

"total is undefined" on this line.

var url = "results2.html" + "?" + total;

companion.js is another good tool.
Copy linkTweet thisAlerts:
@gregmaustinauthorFeb 05.2010 — Alright wow! Its working good now. Thank you so much sir. But the only thing its not doing is its not going to the correct page like anything less than 30 is suppose to go one one page then anything from 30-59 is suppose to go to a different one. and so on... what am i doing wrong? I know it has something to do with the if else statement and the location=url thing.

if (total<30){window.location="results2.html" }

else if (total<60){window.location="results3.html" }

else if (total<90){window.location="results4.html" }

else {window.location="results4.html" }

url = "results4.html" + "?" + total;

window.location=url;

url = "results3.html" + "?" + total;

window.location=url;

url = "results2.html" + "?" + total;

window.location=url; /* it is only listening to this one. I guess I need to state what range i want it to go too if it goes to this one and the range on going to any other pages. but i dont know how? */

}[/QUOTE]
Copy linkTweet thisAlerts:
@harrierdhFeb 08.2010 — I don't know if you got everything working or not. I noticed that you are comparing total to a number. It is really coming in as a string. You will have to convert it to a number.

var numtotal = parseFloat(total);
Copy linkTweet thisAlerts:
@gregmaustinauthorFeb 09.2010 — Do you have a instant messanger program I can contact you on Harrierdh? I saw on your website that you have experience with Oracle. And Oracle is not working with this javascript you have helped me with. Any idea?

I get this error...

"An error occurred while processing the request. Try refreshing your browser. If the problem persists contact the site administrator"
Copy linkTweet thisAlerts:
@harrierdhFeb 09.2010 — Best to contact me by email. I check it frequently. The only IM I have right now is at work and I'd rather not use that for the forum. harrierdh @ comcast (dot) net.

Regarding Oracle. I haven't worked with it for about 3 years.
×

Success!

Help @gregmaustin spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...