[SOLVED] Switch(score)

This is a discussion on "[SOLVED] Switch(score)" within the JavaScript Forum section. This forum, and the thread "[SOLVED] Switch(score) are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Mar 23rd, 2008, 09:52
New Member
Join Date: Mar 2008
Location: Denmark
Age: 30
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Switch(score)

I try to create an IQtest for my homepage, and have downloaded a JavaScript code from another site with permission from the author, but I cant contact the author at his email anymore unfortually, so thats why I place my question in this forum.



Now to the problem:
On my IQtest which is located here http://yalla.dk/projectjs/test.htm ( not finished ) Ive some different cases in my test.js ( see code below ) if the person has 0 correct, it will show this site http://yalla.dk/projectjs/result.html?result=0 - if the person
score 1 correct, it will show this site http://yalla.dk/projectjs/result.html?result=1 and so on. But my problem is when the person score 10 correct ( http://yalla.dk/projectjs/result.html?result=10 ) then the site
display its like only 1 correct, this problem only occure when user get 10 or more correct - mayby its because that 10/11/12 is a two digis number?

I hope you people out there understand what I mean, and can help me to away with this big problem.

test.js

Code: Select all
var answers=new 
Array('D','C','B','D','D','C','C','C','C','C','C','C','C','C','C','C','C','*C','C','C'); 
var query=1; 
var age=location.search.substr(5,1); 
var tick=480; 

function updateAnswer(value) { 
        setFieldValue(eval('document.forms[0].Item' + query), value, true); 
        if(tick>0) { 
                if(query<20) { 
                        query++; 
                } 
                doNavigate(); 
        } 

} 


function doNavigate() { 
        document.getElementById('testcount').innerHTML=query; 
        document.getElementById('testimage').src='gf/item' + query + '.JPG'; 
        var curValue=getFieldValue(eval('document.forms[0].Item' + query)); 
        if(curValue=='') { 
                for(var i=0;i<5;i++) { 
                        document.forms[0].Item[i].checked=false; 
                } 
        } 
        else { 
                setFieldValue(document.forms[0].Item, curValue, true); 
        } 
        if(query<2) { 
                document.getElementById('Previous').style.visibility='hidden'; 
        } 
        else { 
                document.getElementById('Previous').style.visibility=''; 
        } 
        if(query>19) { 
                document.getElementById('Next').style.visibility='hidden'; 
        } 
        else { 
                document.getElementById('Next').style.visibility=''; 
        } 


} 


function countDown() { 
    tick--; 
    var minutes=parseInt(tick/60); 
    var seconds=tick % 60 
    if(seconds<10) {seconds='0' + seconds} 
    document.getElementById('timer').innerHTML=minutes + ':' + 
seconds; 
    if (tick == 0) { 
        alert("Nu har 8 minuter passerat!"); 
        tester(); 
//      document.getElementById('Previous').style.visibility='hidden'; 
//      document.getElementById('Next').style.visibility='hidden'; 
        return; 
    } 
    var command="countDown()"; 
    window.setTimeout(command,1000); 


} 


function tester() { 
        var score=age; 
        var frm=document.forms[0]; 
        for(var i=1; i<=answers.length; i++) { 
                var fld=eval('frm.Item' + i); 
                if(getFieldValue(fld)==answers[i-1]) { 
                        score++; 
                } 
        } 


        switch(score) { 
         default: 
                location.href='result.html?result=0'; 
                break; 
         case 1: 
                location.href='result.html?result=1'; 
                break; 
         case 2: 
                location.href='result.html?result=2'; 
                break; 
         case 3: 
                location.href='result.html?result=3'; 
                break; 
         case 4: 
                location.href='result.html?result=4'; 
                break; 
         case 5: 
                location.href='result.html?result=5'; 
                break; 
         case 6: 
                location.href='result.html?result=6'; 
                break; 
         case 7: 
                location.href='result.html?result=7'; 
                break; 
         case 8: 
                location.href='result.html?result=8'; 
                break; 
         case 9: 
                location.href='result.html?result=9'; 
                break; 
        case 10: 
                location.href='result.html?result=10'; 
                break; 

        } 

} 


function displayResult() { 
        var result=location.search.substr(8,1); 
        document.getElementById('result' + result).style.display=''; 


} 


function isArray(obj) { 
        if(obj.constructor.toString().indexOf("Array") == -1) { 
                return false; 
        } 
        else { 
                return true; 
        } 


} 


function setFieldValue(field, value, replace) { 
        if(field.type) { 
                var fieldType=field.type; 
        } 
        else { 
                var fieldType=field[0].type; 
        } 
        switch(fieldType) { 
                case "text": 
                case "textarea": 
                case "password": 
                case "hidden": 
                        if(replace) { 
                                field.value=value; 
                        } 
                        else { 
                                field.value+=value; 
                        } 
                case "select-one": 
                        if(isArray(value)) { 
                                value=value[0]; 
                        } 
                        for(var i=0; i<field.length; i++) { 
                                if(field.options[i].text==value || field.options[i].value==value) 
{ 
                                        field.options[i].selected=true; 
                                        break; 
                                } 
                        } 
                        break; 
                case "select-multiple" : 
                        var arrFlag=isArray(value); 
                        for(var i=0; i < field.options.length; i++) { 
                                if(field.options[i].selected && replace) { 
                                        field.options[i].selected=false; 
                                } 
                                if(arrFlag) { 
                                        for(var j=0; j<value.length; j++) { 
                                                if(field.options[i].text==value[j] || 
field.options[i].value==value[j]) { 
                                                        field.options[i].selected=true; 
                                                } 
                                        } 
                                } 
                                else { 
                                        if(field.options[i].text==value || field.options[i].value==value) 
{ 
                                                field.options[i].selected=true; 
                                        } 
                                } 
                        } 
                        break; 
                case "button" : 
                case "reset" : 
                case "submit" : 
                        return; 
                case "radio" : 
                        if(isArray(value)) { 
                                value=value[0] 
                        } 
                        for (i = 0; i < field.length; i++) { 
                                if (field[i].value==value) { 
                                        return field[i].checked=true; 
                                } 
                        } 
                        break; 
                case "checkbox" : 
                        var arrFlag=isArray(value); 
                        for(i = 0; i < field.length; i++) { 
                                if(field[i].checked && replace) { 
                                        field[i].checked=false; 
                                } 
                                if(arrFlag) { 
                                        for(var j=0; j<value.length; j++) { 
                                                if(field[i].value==value[j]) { 
                                                        field[i].checked=true; 
                                                        break; 
                                                } 
                                        } 
                                } 
                                else { 
                                        if(field[i].value==value[j]) { 
                                                field[i].checked=true; 
                                                break; 
                                        } 
                                } 
                        } 
                default : 
                        var str = ""; 
                        for (x in field) { 
                                str += x + "\n"; 
                        } 
                        alert("I couldn't figure out what type this field is...\n\n" + 
field.name + ": ???\n\n\n" + str + "\n\nlength = " + field.length); 
        } 


} 


function getFieldValue(field) { 
        if(field.type) { 
                var fieldType=field.type; 
        } 
        else { 
                var fieldType=field[0].type; 
        } 
        switch(fieldType) { 
                case "text": 
                case "textarea": 
                case "password": 
                case "hidden": 
                        return field.value; 
                case "select-one": 
                        var i=field.selectedIndex; 
                        if (i == -1) { 
                                return ""; 
                        } 
                        else { 
                                if(field.options[i].value=='') { 
                                        return field.options[i].text; 
                                } 
                                else { 
                                        return field.options[i].value; 
                                } 
                        } 
                case "select-multiple" : 
                        var allChecked = new Array(); 
                        for(i = 0; i < field.options.length; i++) { 
                                if(field.options[i].selected) { 
                                        if(field.options[i].value=='') { 
                                                allChecked[allChecked.length]=field.options[i].text 
                                        } 
                                        else { 
                                                allChecked[allChecked.length]=field.options[i].value 
                                        } 
                                } 
                        } 
                        return allChecked; 
                case "button" : 
                case "reset" : 
                case "submit" : 
                        return ""; 
                case "radio" : 
                        for (i = 0; i < field.length; i++) { 
                                if (field[i].checked) { 
                                        return field[i].value; 
                                } 
                        } 
                        return ""; 
                case "checkbox" : 
                        var allChecked = new Array(); 
                        for(i = 0; i < field.length; i++) { 
                                if(field[i].checked) { 
                                        allChecked[allChecked.length]=field[i].value; 
                                } 
                        } 
                        return allChecked; 
                default : 
                        var str = ""; 
                        for (x in field) { 
                                str += x + "\n"; 
                        } 
                        alert("I couldn't figure out what type this field is...\n\n" + 
field.name + ": ???\n\n\n" + str + "\n\nlength = " + field.length); 
        }

Last edited by Jack Franklin; Mar 23rd, 2008 at 10:53. Reason: Added [code] tags.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Mar 23rd, 2008, 15:30
New Member
Join Date: Mar 2008
Location: Denmark
Age: 30
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Switch(score)

Hello again.
I will you say that my problem now is solved ;-)

Sorry, Jack Franklin for not putting the JavaScript in the code tags, I will try to remember this next time ;-)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Mar 23rd, 2008, 21:07
Aso's Avatar
Aso Aso is offline
Moderator

SuperMember
Join Date: Oct 2007
Location: UK
Posts: 1,341
Blog Entries: 2
Thanks: 11
Thanked 49 Times in 46 Posts
Re: Switch(score)

Could you post the solution for other users please?
Last Blog Entry: The Google Misconception (Feb 3rd, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Mar 24th, 2008, 07:09
New Member
Join Date: Mar 2008
Location: Denmark
Age: 30
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Switch(score)

Quote:
Originally Posted by aso186 View Post
Could you post the solution for other users please?
The solution was to replace following code.

var result=location.search.substr(8,1);

with

var result=window.location.search.substr(8);

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can you beat my score? Prestonlee Webforumz Cafe 13 Nov 24th, 2007 00:34
Switch to linux? alexgeek Webforumz Cafe 7 Oct 10th, 2007 21:00
switch post alexgeek PHP Forum 12 Sep 25th, 2007 10:04
CSS style switch Heavensword Web Page Design 3 Jul 24th, 2007 15:24
hi score table timmytots PHP Forum 3 Aug 19th, 2006 18:54


All times are GMT. The time now is 08:11.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42