Ir para conteúdo

POWERED BY:

Arquivado

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

gihbatalha

funções

Recommended Posts

em um sistema para vender imoveis

 

primeiro:

escolher se é pra venda ou locação

 

segundo:

ao escolher, ele me mostra os tipo de imoveis disponíveis para a opção, ou seja se você escolher venda, vai mostrar os imoveis (apartamento, casa, ...) disponíveis para venda), até ai tudo certo

 

terceiro:

ao escolher o imóvel, ele me mostra se está em bairro, condomínio ou ambos, ai que está o problema, não consigo fazer aparecer

 

código do formulário

<form action="cliente.php" method='post' name='cliente' >
  <fieldset style='width:30%; float:left; height:130px'>
    <div align="center">Venda ou Locação?<br />
     <table>
       <tr>
         <td><input type='radio' name='venda_loc'  value='venda' id='venda' onclick="validar()" ></td>
         <td>Venda</td>
       </tr>
       <tr>
         <td><input type='radio' name='venda_loc' id='loc' value='locacao' onclick="validar()"/></td>
         <td>Locação</td>
       </tr>
     </table> 
    </div><!-- div venda_loc -->
  </fieldset><!-- fieldset venda_loc -->
  <fieldset style='width:30%; float:left;height:130px'>
    <div align="center" >Tipo do Imóvel?
    <div id='imovel'>
 
     </div><!-- div imovel -->
    </div><!-- div imovel -->
  </fieldset><!-- fieldset imovel -->
  <fieldset style='width:30%; float:left; height:130px'>
    <div align='center'>Bairro ou Condomínio?
      
      <div id='bairro'>
      </div><!-- div bairro_cond -->
     
    </div><!-- div bairro/condominio -->
  </fieldset><!-- fieldset bairro/condominio -->
</form>

função para fazer aparecer os imoveis

function validar(){
	 
   if (document.getElementById('venda').checked == true){
	   var venda_loc = document.getElementById('venda').value;
	  }// se venda estiver selecionado
   if (document.getElementById('loc').checked == true){
	   var venda_loc = document.getElementById('loc').value;
	  }// se locacao estiver selecionado

	  
   if (venda_loc == 'venda'){
        imovel.innerHTML = '<table>'+
		  <?php
		    $sql = mysql_query("select distinct(imovel) from cadastrar_imovel where venda_loc='venda' order by imovel");
			
			  while ($row = mysql_fetch_row($sql)) {
		?>
		  '<tr><td><input type="radio" name="imovel" id="<?php echo $row[0];?>" onclick="validar2()" value="<?php echo $row[0];?>"><?php echo $row[0];?></td></tr>'+
		<?php	
				  }//fim while
		 ?>
		   '</table>';
		  
		  }// se venda_loc for igual a venda
   if (venda_loc == 'locacao'){
	  imovel.innerHTML = 
	   
	    <?php
		  $sql = mysql_query("select distinct(imovel) from cadastrar_imovel where venda_loc='locacao' order by imovel");
		  while ($row = mysql_fetch_row($sql)){
		?>
		  '<input type="radio" name="imovel" id="<?php echo $row[0];?>" onclick="validar2()" value="<?php echo $row[0];?>"><?php echo $row[0];?>'+
	    <?php
		  }// fim while
		?>
	     '</table>';
	  }	// se venda_loc for igual a locacao 

  	  }// function validar

função para fazer aparecer se é bairro ou condominio

function validar2(){
	  
	  if (document.getElementById('apartamento').checked == true){
		  var imovel = document.getElementById('apartamento').value;		  
		  }// se aparatamento estiver selecionado
	  if (document.getElementById('casa').checked == true){
		  var imovel = document.getElementById('casa').value;
		  }// se casa estiver selecionado	  
	  if (document.getElementById('terreno_lote').checked == true){
		  var imovel = document.getElementById('terreno_lote').value;
		  }// se terreno_lote estiver selecionado	  
	  if (document.getElementById('galpao_loja_sala').checked == true){
		  var imovel = document.getElementById('galpao_loja_sala').value;
		  }// se galpao_loja_sala estiver selecionado
	  if (document.getElementById('sitio_chac_faz').checked == true){
		  var imovel = document.getElementById('sitio_chac_faz').value;
		  }// se sitio_chacara_fazenda estiver selecionado
	  
	  if (imovel == 'apartamento'){
		  alert('teste');
		  }
	  
	  }// function validar2

alguém tem ideia de como resolver?

Compartilhar este post


Link para o post
Compartilhar em outros sites

Descobri que do jeito que ta só funciona se tiver todos os imoveis, se faltar um não funciona

 

alguém tem ideia de como fazer funcionar sem ter que ter todos?

Compartilhar este post


Link para o post
Compartilhar em outros sites

consegui fazer verificando se o imovel existe

if (document.getElementById('apartamento') != undefined){	 
	  if (document.getElementById("apartamento").checked == true){
		   imovel = document.getElementById("apartamento").value;		  
		  }// se apartamento estiver selecionado
	}// caso apartamento exista
	
	

	if (document.getElementById('casa') != undefined){	
	  if (document.getElementById("casa").checked == true){
		  imovel = document.getElementById("casa").value;
		  }// se casa estiver selecionado	  
	}// caso casa exista
	
	
 
   if (document.getElementById('terreno_lote') != undefined){
	   if (document.getElementById("terreno_lote").checked == true){
		   imovel = document.getElementById("terreno_lote").value;
		  }// se terreno_lote estiver selecionado	  
	   }//caso terreno_lote exista
	
	 
   
	if (document.getElementById('galpao_loja_sala') != undefined){
		if (document.getElementById('galpao_loja_sala').checked == true){
			 imovel = document.getElementById('galpao_loja_sala').value;
			}// se galpao_loja_sala estiver selecionado
		}// caso galpao_loja_sala exista    
	
	
    if (document.getElementById('sitio_chac_faz') != undefined){
		if (document.getElementById('sitio_chac_faz').checked == true){
			imovel = document.getElementById('sitio_chac_faz').value;
			}
		}// caso sitio_chacara_fazenda exista

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.