Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript_howto thread: SV: functions


Message #1 by "Robert Nyman" <robert.nyman@c...> on Wed, 20 Nov 2002 14:50:17 +0100
This solution isn't going to work correctly either.  It will only return 
the value of radioCheck("rQ6","6") because bOkToSubmit is set to this 
value last.

Try this instead:

function Validate(pham){

	return (radioCheck("rQ1","1") && radioCheck("rQ1","1") && 
radioCheck("rQ1","1") && radioCheck("rQ1","1") && radioCheck("rQ1","1") 
&& radioCheck("rQ1","1"));

}

> Yes, if you use the return statement it ends the execution of the
function there.

Code it like this instead:

function Validate(pham){
	var bOkToSubmit =3D false;
	bOkToSubmit =3D radioCheck("rQ1","1");
	bOkToSubmit =3D radioCheck("rQ2","2");
	bOkToSubmit =3D radioCheck("rQ3","3");
	bOkToSubmit =3D radioCheck("rQ4","4");
	bOkToSubmit =3D radioCheck("rQ5","5");
	bOkToSubmit =3D radioCheck("rQ6","6");
	return bOkToSubmit;
}


/Robert


-----Ursprungligt meddelande-----
Fr=E5n: Pham, Khanh [mailto:Khanh.Pham@d...]=20
Skickat: den 19 november 2002 21:04
Till: JavaScript HowTo
=C4mne: [javascript_howto] functions


Can someone tell me what is wrong with this code.  I am validating
sections of radio buttons.  I create a function called "radioCheck(x,z)"
and a function called "Validate()".  It just calls radioCheck once from
validate and submits the form.

Thanks all.
*********************************************************************
<script language=3D"JavaScript">
function Validate(pham){
	return radioCheck("rQ1","1");
	return radioCheck("rQ2","2");
	return radioCheck("rQ3","3");
	return radioCheck("rQ4","4");
	return radioCheck("rQ5","5");
	return radioCheck("rQ6","6");
}
function radioCheck(x,z){
	useroption =3D -1
	for(i=3D0; i<eval("document.frmSurvey."+x+".length"); i++){
		if (eval("document.frmSurvey."+x+"[i].checked")){
			useroption =3D i; 		=09
			break;
			return false
		}
	}
	if(useroption =3D=3D -1){
		alert("Please answer Question "+z+".")
		eval("document.frmSurvey."+x+"[0].focus();")
		return false;
	}

}
</script> *************************************************************8

---
Change your mail options at http://p2p.wrox.com/manager.asp or=20
to unsubscribe send a blank email to



  Return to Index