Page 1 of 1

undefined function

Posted: Mon Jun 11, 2007 12:45 pm
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]

Posted: Mon Jun 11, 2007 1:19 pm
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.

Posted: Mon Jun 11, 2007 3:06 pm
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.