Become a MacRumors Supporter for $25/year with no ads, private forums, and more!

Mac Java Questionnaire...

TENBLUE7™

macrumors member
Original poster
Nov 4, 2003
98
0
Sheffield - England
...Hello All.

Well out of my depth here doing the usual forms in php and such, so any help would be much appreciated.

I've been asked by a client to produce a questionnaire using radio boxes that are scored from 5 to 1, and there's 24 questions in total. And a number of html pages that are called on depending on the final score.

I've modelled the new doc on an old one based on 11 questions, it's returning a value but always the same and I have no idea what this means below:

<script language="JavaScript">

aLinks = new Array("24-40.html","41-60.html","61-80.html","81-120.html");

function CheckForm(){
var errString = "";
var iScore=0;
for (iRad = 1; iRad < 24; iRad ++){
bFlag = false;
iScr = 0
myArray = document.Form1.elements["val" + iRad];
for (iVal = 0; iVal < 5; iVal ++){
if (myArray[iVal].checked){
bFlag = true;
iScr = parseInt(myArray[iVal].value);
}
}
if (!bFlag){
errString = "Please ensure you provide an answer for each question!";
}
iScore += iScr;
}
if (errString != ""){
alert (errString);
}
else {
iScore = Math.ceil((iScore - 24)/24)-1;
iScore = (iScore == -1 ? iScore = 0 : iScore = iScore);
window.open(aLinks[iScore],'RCHPOP2','scrollbars=1,resizable=0,menubar=0,toolbar=0,status=0,location=0,directories=0,width=670,height=300');
}
}

</script

This is the easy part he wants the forms returned to be dependant not only the total score but on certain scores for certain questions. god help me.

Thanks
 

TENBLUE7™

macrumors member
Original poster
Nov 4, 2003
98
0
Sheffield - England
Just to add I know it's java so I'm not that bad :rolleyes: and the 24 value represents that total number of questions represented by the radio buttons this I've figured out through trial and error I can't understand why it's always returning the 41-60.html doc regardless of the scores.

Thanks
 
Comment

haym37

macrumors newbie
Feb 19, 2005
5
0
TENBLUE7™ said:
Just to add I know it's java so I'm not that bad :rolleyes: and the 24 value represents that total number of questions represented by the radio buttons this I've figured out through trial and error I can't understand why it's always returning the 41-60.html doc regardless of the scores.

Thanks

Actually, it's not Java. It's JavaScript. You may want to try posting this (or moving it, if you can) to the Web Design and Development Forum.
 
Comment

superbovine

macrumors 68030
Nov 7, 2003
2,872
0
you should use the code tags next time. it will be easier to read. :D

like this:

Code:
#include <iostream>

using namespace std;

int main() {

  cout << "I am a cow!" << endl;
  
  return 666;

}
 
Comment

broken_keyboard

macrumors 65816
Apr 19, 2004
1,144
0
Secret Moon base
It always returns the second page because "iScore = iScore" evaluates to 1 which is the index of the second page. It should just say
iScore = (iScore == -1 ? iScore = 0 : iScore);
and the second 24 in the line above should be (120 - 24).


But that whole approach assumes that each page covers the same range of scores, which it doesn't: the first is 17, the second is 20 etc.

So you need to replace the whole last "if" block with something simple like:

page = "";
if ( iScore >= 24 && iScore <= 40 ) {
page = "24-40.html";
} else if ( iScore >= 41 && <= 60 ) {
page = "41-60.html";
} etc...

window.open(page, ... )
 
Comment

VanMac

macrumors 6502a
May 26, 2005
914
0
Rampaging Tokyo
haym37 said:
He's looking for JavaScript support, as I stated, not Java support.
Yes, I know.
If you would have read my post, it said ANYONE looking for Java support would make good use of the sun forums. It was just an FYI.
 
Comment
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.