Getting fustrated with this javascript code

This is really getting to me now… I have been on this site and have been on tutorial for javascript to find a way to do this and I am really running out of time…I am trying to use javascript to validate all of the fields on the form that the questions have values in it, it should not be this complicated!!! I use a submit button with the filesave and file close command

I have a field on the form that tells me the what question is the last one.

I am trying to loop through the fields but I am getting errors… I am not even sure if I am placing the code at the right place…

Here is what I have so far…

The fields are Answer1 to Answer50

All of the Answer fields are radioButtons………

<input name=“LastPage” value=“” id="LastPage_field"type=“hidden”>

I have this in the submit button

for (i==1; i<=20; i++){

answer = document.getElementsByName(“Answer”+i).item(0).value;

alert(answer);

if (answer == null) {

return alert(‘You passed!’)

} else {

return alert(‘You failed!’)

}

}

When it fails it should be return false

If anyone can help me with this code…. It would be very appreciated….

Alena,

Subject: Getting fustrated with this javascript code…

You can download a javascript function called getFieldValue from the following url :Get Field Value

It can validate all types of field, so its quite handy.

Once you have done that, put it into the JS Header.

Following is the code which validates Answer1 to Answer20

for ( i=1 ; i<21 ; i++ ) {

	fieldObj = document.all("Answer"+i)

	if ( getFieldValue( fieldObj ) == "" ) {

		alert ( "Please select a value for Answer No: " + i )

		return false;

	}

}

return true;

cheers!!

Ashish

Subject: RE: Getting fustrated with this javascript code…

LoNo, this is greate it is working… wow…

only one thing… I tought that I had the answer for the page number but it gives me an undefined message… here is what I am doing.

I have this code at the top of my form, so I know what number is the last page…

<input name=“LastPage” value=“” id="LastPage_field"type=“hidden”>

I have tried this… and I want my LastPage to let me know when to stop the for loop… but it is not working… obviously I am not using the right code to get the value of that field…

alert(PageNumber.value);

for ( i=1 ; i<PageNumber ; i++ ) {

fieldObj = document.all(“R”+i)

if ( getFieldValue( fieldObj ) == “” ) {

alert ( "Please select a value for Answer No: " + i )

return false;

}

}

return true;

thanks again for the greate help so far… it is very much appreciated…

Alena,

Subject: RE: Getting fustrated with this javascript code…

I presume you are using PageNumber as a javascript variable. And the field which contains the Last Page value is called LastPage, so try the following :

PageNumber = document.forms[0].LastPage.value

alert(PageNumber)

Regarding the undefined message:

alert(PageNumber.value); is the culprit

cheers!!

Ashish

Subject: RE: Getting fustrated with this javascript code…

That is greate the javascript is now working thanks so much…

I still have an issue with my code… does it ever end…

I am trying to write to the document so that on the $$return I would tell the user if they pass or failed… I dont seem to have access to the field on the document

I have a field call CorrectAnswers on the form and it contains the correct answers from the quiz, I also have a field call WebCorrectAnswer this is to hold all of the answers from the users selection on the web, in that field I have Answer1: Answer2… I am not even sure if it is being set , cause I cannot see it from the print statement. I wuold think that the script is good… but i guess not. any ideas LoNo again…

Dim session As NotesSession

Set session = New NotesSession

Dim doc As NotesDocument

Set doc = session.DocumentContext

PageNumber = doc.GetItemValue("LastPage") 



Print PageNumber 

Dim matchs As Integer



matchs = 0

Forall i In PageNumber

	Print "i" & i  ' i is 11, I would think that i is 1 

	If doc.WebCorrectAnswer(i) = doc.CorrectAnswers(i) Then

		test = doc.WebCorrectAnswer(i) ' test is showing nothing on the print...

		Print "test" & test

		matchs = matchs + 1

		Print  matchs & "matchs"

		doc.matchs = matchs

		

		If Cint(PageNumber/2) >= matchs Then

			doc.PassQuestion = "Pass"

		Else

			doc.PassQuestion = "Failed"

		End If

	End If

	

End Forall

Subject: RE: Getting fustrated with this javascript code…

I got things to work… thanks for your help LoNo…