Jump to content

Calling function via a switch does not seem efficient


sKunKbad

Recommended Posts

I'm wondering if there is a more efficient way to call one of the functions in the switch statement below (but without using eval(), or is eval() the best way to go?

 

I just basically need to do a little client side validation in a multi page form, and if the processing function returns true or false, I'll either send the user to the next page or output error messages.

 

switch(page){
case '1':
	var processing_function = part_1();
	break;
case '2':
	var processing_function = part_2();
	break;
case '3':
	var processing_function = part_3();
	break;
case '4':
	var processing_function = part_4();
	break;
case '5':
	var processing_function = part_5();
	break;
case '6':
	var processing_function = part_6();
	break;
case '7':
	var processing_function = part_7();
	break;
case '8':
	var processing_function = part_8();
	break;
case '9':
	var processing_function = part_9();
	break;
case '10':
	var processing_function = part_10();
	break;
}

if( processing_function ){
// Do something
});

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.