Jump to content

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
});

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.