Java Questionnaire...

Discussion in 'Mac Programming' started by TENBLUE7™, Aug 27, 2005.

  1. TENBLUE7™ macrumors member

    Joined:
    Nov 4, 2003
    Location:
    Sheffield - England
    #1
    ...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
     
  2. TENBLUE7™ thread starter macrumors member

    Joined:
    Nov 4, 2003
    Location:
    Sheffield - England
    #2
    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
     
  3. haym37 macrumors newbie

    Joined:
    Feb 19, 2005
    #3
    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.
     
  4. superbovine macrumors 68030

    superbovine

    Joined:
    Nov 7, 2003
    #4
    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;
    
    }
     
  5. VanMac macrumors 6502a

    VanMac

    Joined:
    May 26, 2005
    Location:
    Rampaging Tokyo
    #5
  6. broken_keyboard macrumors 65816

    broken_keyboard

    Joined:
    Apr 19, 2004
    Location:
    Secret Moon base
    #6
    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, ... )
     
  7. haym37 macrumors newbie

    Joined:
    Feb 19, 2005
    #7
    He's looking for JavaScript support, as I stated, not Java support.
     
  8. VanMac macrumors 6502a

    VanMac

    Joined:
    May 26, 2005
    Location:
    Rampaging Tokyo
    #8
    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.
     

Share This Page