Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: SV: Syntax for Switch/Case Statement


Message #1 by "Robert Nyman" <robert.nyman@c...> on Fri, 17 Jan 2003 10:15:04 +0100
To have many alternatives that result in the same thing, write them like
this:

switch(document.bus_data_form.employee_subgroup.selectedIndex){
		case 1:
		case 2:
		case 3:
		case 4:
		case 5:
		case 6:
			document.bus_data_form.recipient.value =3D
payroll;
			break;
		case 7:
		case 8:
		case 9:
			alert("This combination is not routable. Please
correct one of these fields.");
			return false;		=09
}

See
http://developer.netscape.com/docs/manuals/js/core/jsref15/stmt.html#101
8610

In your particular example, an if clause might me much easier. As in:

if(new
String(document.bus_data_form.employee_subgroup.selectedIndex).search(/[
1-6]/) !=3D -1){
	document.bus_data_form.recipient.value =3D payroll;
}
else if(new
String(document.bus_data_form.employee_subgroup.selectedIndex).search(/[
7-9]/) !=3D -1){
	alert("This combination is not routable. Please correct one of
these fields.");
	return false;=09
}


/Robert


-----Ursprungligt meddelande-----
Fr=E5n: Azinger, Richard [mailto:richard.azinger@p...]
Skickat: den 16 januari 2003 23:05
Till: javascript
=C4mne: [javascript] Syntax for Switch/Case Statement



Hello list,

What is the correct syntax for the switch/case statement where multiple
cases do the same thing?

Here is my code that doesn't work. It only works for 6 & 9.

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

	switch(document.bus_data_form.employee_subgroup.selectedIndex){
		case 1,2,3,4,5,6 :
			document.bus_data_form.recipient.value =3D
payroll;
			break;
		case 7,8,9 :
			alert("This combination is not routable. Please
correct one of these fields.");
			return (false);
			break;
		}


=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

Thanks for any help,

Rich Azinger


This communication is for use by the intended recipient and contains
information that may be privileged, confidential or copyrighted under
applicable law.  If you are not the intended recipient, you are hereby
formally notified that any use, copying or distribution of this e-mail,
in whole or in part, is strictly prohibited.  Please notify the sender
by return e-mail and delete this e-mail from your system.  Unless
explicitly and conspicuously designated as "E-Contract Intended", this
e-mail does not constitute a contract offer, a contract amendment, or an
acceptance of a contract offer.  This e-mail does not constitute a
consent to the use of sender's contact information for direct marketing
purposes or for transfers of data to third parties.

 Francais Deutsch Italiano  Espanol  Portugues  Japanese  Chinese
Korean

            http://www.DuPont.com/corp/email_disclaimer.html






  Return to Index