18 Replies Latest reply on Jul 15, 2015 4:31 AM by JohnnyBQue

# can someone tell me if this would work...andif not why....

I want to grade a test that uses radio buttons to indicate the answers...there are 58 questions with five answers to select from for each question...I'm using a button that when clicked it will look at the radio buttons that ARE the correct answers and if they are selected a counter is increments by 1 if the correct answer is not selected there will be no increment.

This will allow me to perform a simple match calculation to achieve a test score. I'm not a programmer but I'm learning thanks to you guys on the forums...so what I got so far is below let me know if I'm on the right track ....My issue is how to develop a counter that will store the increments and allow me to use the results in a formula then place that number in a text box to be displayed ( I can probably figure the text box display thing out).

Name: Q1

Tooltip: Question 1

Button Style: Circle

Var Grade = 0;                             //don't know how to declare this variable should it be 0 only to have the else statement make it 0

If(Answer =="a") {             // "a" is the correct answer this time but will vary from a, b, c, d, e not sure how to loop so is my only other choice is to dupi such as Var Answer1, Var Answer 2, etc...

}

else {Grade = "0",           // not sure if I even need the or else

}

I would perform this for each question because coding an array is beyond my abilities...

Here's my attempt at a counter

Var CounterCorrectAnswer = 0                                                     // sets the counter to Zero? correct

for (var i =1; i <= 58; i++){                                                           // set the value of i to 1 and the number of times to count to 58?...is the i++ means to increment i by 1 if the results = "2" ???

`var result = this.getField("Grade" + i).value;   //now does the var Grade above get 1 added to it here..???..so what does ".value" represent hereif (result == "2") {                             // verifying that var result equals "2"    CounterCorrectAnswer++                        //if result equals "2" then increment counterCorrectAnswer to 1...?     }`

this.getField("SumCorrect").value = CounterCorrectAnswer;   // SumCorrect will be the text box field that holds the total number of correct answers.

what confuses me again  is how do I loop through the questions "Q1 thru Q58" to see if the right answer was selected.

• ###### 1. Re: can someone tell me if this would work...andif not why....

This is what I got so far....I keep getting a syntax error noted below

//else

for (var i = 1; i ,= 58; i++){

var result = this.getField("Grade" + i).value;        // I get a syntax error here

if (result == "2")

• ###### 2. Re: can someone tell me if this would work...andif not why....

I didn't read the entire thing but the first error is in the first line... Look carefully and read the text of the error message.

• ###### 3. Re: can someone tell me if this would work...andif not why....

i ,= 58 makes no sense

• ###### 4. Re: can someone tell me if this would work...andif not why....

yep should be

now in debugger placing the cursor and the end of this line and hit num-pad enter button I get "undefined"

now here a funny thing if I do not select any of the radio buttons in the form and place the cursor at the end of the code I get a 0 return but if I select the correct answer i get a 1 return which is what I was wanting bu the code still has a number of undefined issues...

errors I get based on hitting num-pad enter button at the end of each line

if (Answer == "a")                                            SyntaxError: syntax error 2: Console:Exec undefined

else                                                                SyntaxError: syntax error 1: Console:Exec undefined

for(var i =1; i<= 58; i++)                                     SyntaxError: syntax error 2: Console:Exec undefined

{var result = this.GetField("Grade" + i).value;}      ReferenceError: i is not defined 1:Console:Exec undefined

if(result == "2")                                                  SyntaxError: syntax error 2: Console:Exec undefined

this.getField("SumCorrect").value = CounterCorrectAnswer;  1   (I get a 1 here because the correct answer radio button is selected if  unselected it I get a 0) 1 and 0 shows in the text box also....

answer me this when using the debugger if the cursor is at the end of the line of code is the error returned for that line or the end of that line and above meaning the

• ###### 5. Re: can someone tell me if this would work...andif not why....

yeah that was a type-O it should have been "i<=58" I corrected that

• ###### 6. Re: can someone tell me if this would work...andif not why....

You can't run each line of code separately. You need to run the entire thing as a whole. What happens when you do that?

And "undefined" just means the code executed without errors and without returning any values.

• ###### 7. Re: can someone tell me if this would work...andif not why....

placing the cursor at the end of the code and pressing the num-pad enter I get the following error:

1:Console:Exec

undefined

• ###### 8. Re: can someone tell me if this would work...andif not why....

You need to select the entire code if you want to run all of it.

• ###### 9. Re: can someone tell me if this would work...andif not why....

First select all lines then execute the code.

• ###### 10. Re: can someone tell me if this would work...andif not why....

okay selected all the code and presses the num-pad enter key and got

TypeError: this.GetField is not a function

16:Console:Exec

undefined

• ###### 11. Re: can someone tell me if this would work...andif not why....

JS is case-sensitive. The name of the function is getField, not GetField...

• ###### 12. Re: can someone tell me if this would work...andif not why....

Fixing the the error turns into the following...

TypeError: this.getField("Grade" + i) is null

13:Console:Exec

undefined

I thought "Grade" was returning a 1 value because the radio button that was selected is the correct one var Answer = this,getField(Q1").value;    Answer == "a" which what is selected at the time I ran the code...

• ###### 13. Re: can someone tell me if this would work...andif not why....

That means you're trying to access a field which doesn't exist.

• ###### 14. Re: can someone tell me if this would work...andif not why....

then changed the code the was returning a "Null" to

{var result = this.getField("Gradecount" + i).value;

now I get this error never seen it before....

SyntaxError: invalid assignment left-hand side

11:Console:Exec

undefined

• ###### 15. Re: can someone tell me if this would work...andif not why....

You need to post the full code, or at least the lines around the one where the error message appears (line 11, in this case).

• ###### 16. Re: can someone tell me if this would work...andif not why....

else

for(var i = 1; i <= 58; i++)

{var result = this.getField("Gradecount" + i).value;}

if(result == "2")

ran it as posted above ...see in BOLD above and found it... I didn't add ".value" and the end of ("Gradecount")

but when I run it I still get the null error (see below) now I create a textbox called Gradecount and the code above this.getField("Gradecount").value = Grade; has assigned the value 1 which shows in the textbox so why can't I add "i" to it which should be 1 also from the "for" statement above?

TypeError: this.getField("Gradecount" + i) is null

22:Console:Exec

1

• ###### 17. Re: can someone tell me if this would work...andif not why....

Also, this code needs to be inside of the for-loop code block:

So it needs to be:

for (var i = 1; i <= 58; i++) {

var result = this.getField("Gradecount" + i).value;

if (result == "2")