Validation with Javascript not working

I am trying to validate the form so that mandatory fields are filled, some how it does not allow me to add the Return True and Return False… Also mandatory fields are mandatory when there is a question in the QuestionField

the form looks like this

Question1

R1

Question2

R2

up to 30 questions…

// Check each of the required fields and return and error listing any mandatory fields that fail validation

var errString;

var frm = document.forms[0];

var flds = new Array();

// validate the listbox field first, then the remaining fields

// validate the radio button fields

var r1 = document.forms[0].R1.length;

var i;

var y;

y = “0”

for(i = 0; i<r1; i++)

{

if(document.forms[0].R1[i].checked)

{

y = y + “1”

}

y = y + “0”

}

if (y == “000”) // 3 zeros means that there was no selection made in the radio button field

{

errString = errString + "please enter..." ?" + '\r\n'

}

var r1 = document.forms[0].R2.length;

var i;

var y;

y = “0”

for(i = 0; i<r1; i++)

{

if(document.forms[0].R2[i].checked)

{

y = y + “1”

}

y = y + “0”

}

if (y == “000”) // 3 zeros means that there was no selection made in the radio button field

{

errString = errString + "please enter..." + '\r\n'

}

…

… it goes up to 30 fields

// list text fields to validate below

// The text in quotes is what is added to to errString and returned to the user.

flds[flds.length] = [frm.R1, “aaaaaa”];

flds[flds.length] = [frm.R2, “aaa”];

…

…

// loop through the array of fields validating each one

for (var i = 0; i < flds.length; i ++)

{

if ( flds[i][0].value == “” )

{

//if the field fails validation, add it to the string

errString = errString + flds[i][1] + '\r\n' ; 	

}

}

if (errString == “”) // if nothing is added to the errString, all fields passed validation, if not return the list of fields that failed

{

return true	;

}

{

// return one alert box with the list of fields that failed validation

alert("The following information is required:" + '\r\n' + errString)

return false;

}



It does not let me save the return.....

Any ideas…

A.

Subject: Validation with Javascript not working.

which event are you trying to write this script in … Is there some other function also which is called after this script …

Subject: RE: Validation with Javascript not working.

Hi,

I have put the code in the on submit event…

There is no other function being called after… I want to make sure that they enter values in the radio button fields answers that have a Questions in the Question field.

Subject: RE: Validation with Javascript not working.

Use an alert after each if block like this

window.alert(“Pased First If Block”);

window.alert(“Pased Second If Block”);

etc.

Shawn

Subject: RE: Validation with Javascript not working.

Check if the JavaScript code is getting triggered or not by putting an alert statement in the first line of the cod e.g.

alert(“First Line Of The Code”);

If it is not getting triggered then possibility is that you have written the code on the client. Check if the Web is selected in the “Run” above where the JavaScript code is written on Submit event.

Let me know if the issue still persists or is solved.