undefined function

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

undefined function

Post by bouncer »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

function carregaCombo1(parValor){

		size = frm.produto.length;
		for (i = size; i > 0; i--) {
			 frm.produto[i-1] = null;
		}	
		
		frm.produto.options[0] = new Option("                 ","-1");
				
		if (parValor != "-1"){
		   valor = parValor;
		   eval("size = familia"+valor+".length");
		   if (size == 0){
			  return false;//frm.produto.options[0] = new Option("                 ","-1");
		   }else{   	  
			  eval ("nome = familia"+valor);
			  eval ("codigo = cfamilia"+valor);
			  for (i = 1; i <= size; i++) {
			
				eval("frm.produto.options[i-1] = new Option((nome)[i-1],(codigo)[i-1])");
			
			  }
		   }
		}

}

function listDefault(){

	valor = document.frm.familia.value;
	eval("size = familia"+valor+".length");
				
	frmProduto = document.frm.produto;		
	frmDefault = document.frm.defaultP;
	
	for (i = frmDefault.length; i > 0; i--) {
		 frmDefault[i-1] = null;
	}
	
	frmDefault.options[0] = new Option("---- Escolha ----","-1");
	w=1;		
	for(i=0; i < frmProduto.length; i++){
	                if (frmProduto.options[i].selected == true) {
	                     codProd = frmProduto.options[i].value;
		     for (j = 0; j < size ; j++) {
			eval ("nome = familia"+valor);
			eval ("codigo = cfamilia"+valor);
				if (codProd == codigo[j]){				
					nameProd = nome[j];				
				}			
		    }
				
		eval("frmDefault.options[w] = new Option(nameProd,codProd)");
		w++;		
	}
}
i'm getting problem in this code, undefined function in carregaCombo1 and ';' expected ... did i make something wrong in the first part of the code ?

regards


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Last edited by bouncer on Tue Jun 12, 2007 11:25 am, edited 1 time in total.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

I can't make sense of your code. Are you trying to mix PHP with Javascript?

Edt your code to use the syntax/php tags, also check your code in an editor with syntax highlighting, that will probably solve something.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

In JavaScript, once there is an error in or around a function, the function becomes undefined. So, you have a syntax error either in or before the function.

My guess would be that you haven't properly define the variables within the method's scope. JavaScript is not PHP you know. You have to use the var keyword to initialize variables before using them.
Post Reply