Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

kroppdesign

Select. 3 campos em Javascript.

Recommended Posts

Olá galera, estou com um site e consegui fazer um select de dois campos de veículos, ou seja, quando seleciono o tipo, aparece a marca. Porém quando seleciono a marca preciso que chame o modelo também, mas tudo que faço da erro. Estou enviando a função responsável para vcs darem uma olhada. Tem q fazer mais um select de mais uma tabela do banco nessa função, e criar mais uma variavel la em cima, que seria a tipos, como sub da sub select.

function CreateJsString(){		global $AllModels;						   $this->listing =   "		<!--		  function Fill_Sub1(formf) {		   var main_select = document.getElementById(formf).makems;		   var sub_select = document.getElementById(formf).models;		   if( main_select.options[main_select.selectedIndex].value == 0 )		   {			sub_select.length = 0;		   		   		   }\n";		 		   $this->_db->query("SELECT id,makename FROM ".TABLE_PREFIX."makes order by makename");		   $this->_db2 = new DBM;		   $this->_db2->connect();			while( $Row1 = $this->_db->_fetch_row('DB_FETCH_ASSOC')){		   $this->listing .=   "if(main_select.options[main_select.selectedIndex].value == \"$Row1[id]\")			 {				sub_select.length = 0;\n";				$this->listing .=  "sub_select.options[0] = new Option('$AllModels');\n";				$this->listing .=  "sub_select.options[0].value = '0';\n";				//$selectedctrl=0;				$Query2 = "select modelid,modelname,make_id from ".TABLE_PREFIX."models where make_id = '".$Row1['id']."' order by modelname";				$Result2 = $this->_db2->query($Query2);				$ctr1 = 1;				While( $Row2 = $this->_db2->_fetch_row('DB_FETCH_ASSOC')){					//$this->listing .=  "alert('$Row2[modelname]');";					$this->listing .=  "sub_select.options[$ctr1] = new Option('{$Row2[modelname]}');\n";					$this->listing .=  "sub_select.options[$ctr1].value = '{$Row2[modelid]}';\n";					if($this->modelid == $Row2['modelid']){						  $selectedctrl3=$ctr1;						  $this->listing .= "sub_select.options[$selectedctrl3].selected=true;\n";					  } else {						  $selectedctrl3=0;					  }							$ctr1++;				}			$this->listing .=  "} else \n";			}						$this->listing .=  " {\n";			$this->listing .=  "	sub_select.length = 0;\n";					$this->listing .= "	 sub_select.options[0] = new Option('$AllModels');\n";			$this->listing .= "	 sub_select.options[0].value = '0';\n";					$this->listing .=  "}\n";			$this->listing .=  "	}\n";			$this->listing .=  "Fill_Sub1('{$_GET['fn']}')					-->\n";	return $this->listing;	}

Compartilhar este post


Link para o post
Compartilhar em outros sites

agora alterei a função e tentei fazer a inserção do terceiro campo, porém agora ta dando erro "Parse error: syntax error, unexpected ';', expecting T_FUNCTION in C:\xampplite\htdocs\meucar\admincp\models_cls.php on line 38" porém nao tem nada faltando, acreditem, e essa linha é a última do código, que nao tem nada, e a função é bem no começo....

 

vejam como ficou

 

function CreateMJsString(){		global $AllMakes;		global $AllModels;				   $this->listing =   "		<!--		  function Fill_Sub1(formf) {		   		   		   var main_select = document.getElementById(formf).tipos;		   		   var sub_select = document.getElementById(formf).makems;		   		   var subb_select = document.getElementById(formf).models;		   					 			if( main_select.options[main_select.selectedIndex].value == 0 )		   {			sub_select.length = 0;}\n";				 					   $this->_db->query("SELECT tid,tiponame FROM ".TABLE_PREFIX."tipo order by tiponame");		   $this->_db2 = new DBM;		   $this->_db3 = new DBM;		   		   $this->_db2->connect();		   $this->_db3->connect();			while( $Row1 = $this->_db->_fetch_row('DB_FETCH_ASSOC')){		   $this->listing .=   "if(main_select.options[main_select.selectedIndex].value == \"$Row1[tid]\")			 {				sub_select.length = 0;\n";				$this->listing .=  "sub_select.options[0] = new Option('$AllMakes');\n";				$this->listing .=  "sub_select.options[0].value = '0';\n";				//$selectedctrl=0;				$Query2 = "select id,makename,tipo_tid from ".TABLE_PREFIX."makes where tipo_tid = '".$Row1['tid']."' order by makename";				$Result2 = $this->_db2->query($Query2);				$ctr1 = 1;				while( $Row2 = $this->_db2->_fetch_row('DB_FETCH_ASSOC')){													$this->listing .=   "if(sub_select.options[sub_select.selectedIndex].value == \"$Row2[id]\")			 {				subb_select.length = 0;\n";				$this->listing .=  "subb_select.options[0] = new Option('$AllModels');\n";				$this->listing .=  "subb_select.options[0].value = '0';\n";								$Query3 = "select modelid,modelname,make_id,tipo_id from ".TABLE_PREFIX."models where make_id = '".$Row2['id']."' order by modelname";				$Result3 = $this->_db3->query($Query3);				$ctr1 = 1;				while( $Row3 = $this->_db3->_fetch_row('DB_FETCH_ASSOC')){																						if($this->modelid == $Row3['modelid']){						  $selectedctrl3=$ctr1;						  $this->listing .= "subb_select.options[$selectedctrl3].selected=true;\n";																																				  } else {						  $selectedctrl3=0;					  }							$ctr1++;				}			$this->listing .=  "} else \n";			}						$this->listing .=  " {\n";			//$this->listing .=  "	sub_select.length = 0;\n";			$this->listing .=  "	subb_select.length = 0;\n";					$this->listing .= "	 subb_select.options[0] = new Option('$AllModels');\n";			$this->listing .= "	 subb_select.options[0].value = '0';\n";			//$this->listing .= "	 sub_select.options[0] = new Option('$AllMakes');\n";			//$this->listing .= "	 sub_select.options[0].value = '0';\n";					$this->listing .=  "}\n";			$this->listing .=  "	}\n";			$this->listing .=  "Fill_Sub1('{$_GET['fn']}')					-->\n";	return $this->listing;	}

Compartilhar este post


Link para o post
Compartilhar em outros sites

pq no meu caso se você ver o tipo eh uma tabela, a marca eh outra e o modelo outra....eles se relacionam por ID's...e tem muita variavel ai q nao posso mexereu só queria inserir a tabela do tipo no modelo de cima, acima de todas...la esta marca/modeloquero fazer tipo/marca/modelo

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.