Radio Button field validation in web

Hi,I am trying to check whether a field’s (Type Radio Button) value is blank or not in web.

Java script cannot trap the field value of a radio button field.

So I tried to write the following code in the HTML Head Content of the form and then called the function in the onSubmit event of the form, but its generating error, in the status bar of IE its showing “Object Required” pls help.

x := @Text (SupervisorLevel);

y := @If ( x = “” ; @ERROR ; x);

“<script language="JavaScript" >” + @NewLine +

"<!-- " + @NewLine +

“function checkSupervisorLevel() {” + @NewLine +

“var form = document.forms[0];” + @NewLine +

“var supervisorcheck = "0";” ; + @NewLine +

@If(@IsError(y); @Return (“”);“”) + @NewLine +

“if(supervisorcheck == "1") {return true} else {alert("** You need to select a Supervisory Level **";); return false;}” + @NewLine +

“}” + @NewLine +

“// -->” + @NewLine +

“”

Subject: Radio Button field validation in web.

Suggest you use the JSHeader for the form, not the HTML Head Content - this will make it easier to write your JavaScript and will place it in the block automatically.

Here is a site that provides info on how to verify through Javascript if a radio button has been selected - http://www.sitepoint.com/article/javascript-101-3/5

Based on the info there, if my radiobutton field is named SupervisorLevel, I can have the following in the JSHeader

function checkradio() {

var radioSelected = false;

for (var i=0; i<document.forms[0].SupervisorLevel.length; i++) {

if (document.forms[0].SupervisorLevel[i].checked) radioSelected = true;

}

if (!radioSelected) {

alert(“Please select a radio button.”);

return false;

}

}

And my onSubmit has return checkradio()

Subject: RE: Radio Button field validation in web.

Thanks it worked

Subject: RE: Radio Button field validation in web.

Hi,

I am facing another problem. since I am calling the function in the onSubmit event of the form, the form gets submitted even if it does not pass the validation.

Subject: What is in your onSubmit event?

your onSubmit event should have the following

return checkradio()

Subject: RE: What is in your onSubmit event?

if(checkForm()) {if (checkradio()){

		updateOrderField() ;

		return true;

}else{

		return false;

		}

}else

{

return false; }

Subject: RE: What is in your onSubmit event?

Not really sure why your code is failing, but the Javascript code is processed by the browser, not Domino. Suggest you use the format

return functionname() as your onSubmit code and move your other code into the function you are calling.

Subject: RE: What is in your onSubmit event?

Hi,

I tried it but the problem exists. When I transfered the on submit code to a button, it throwing error saying that the object does not support the property or method.

Subject: RE: What is in your onSubmit event?

Hi,

Its solved, its not possible to transfer focus for a radio button.