Ir para conteúdo

POWERED BY:

Arquivado

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

TiagoMaker

Ao selecionar valor de um select abre outro

Recommended Posts

Dae galera, estou tentando fazer um cadastro de produto e quantidade que ao selecionar um produto no select, abre outro abaixo e assim por diante até o limite de 5 produtos. O código que estou usando não tá abrindo o campo extra.

 

function show(){  
	if(document.getElementById('produto1').selected){  
    	document.getElementById('label').style.display = 'table-row';  
        document.getElementById('campo').style.display = 'table-row';
		document.getElementById('linha').style.display = 'block';
	}else{  
        document.getElementById('label').style.display = 'none';  
        document.getElementById('campo').style.display = 'none';
		document.getElementById('linha').style.display = 'none';
    }  
}

essa é a parte da pagina que tem o formulario

<form name="movimento" id="form1" action="movimento_grava.php" method="post">
<table background="imagens/movimento.png" width="700" height="325" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000">
<tr><td colspan="3" align="center"><b>LANÇAR MOVIMENTO</b><BR><BR></td></tr>
<tr>
	<td width="200" align="right">DATA: </td>
	<td width="500" colspan="2" align="left"><span id="sprytextfield1">
    <input name="data" type="text" size="10" maxlength="10" value="<?php echo $data?>"> <span class="textfieldRequiredMsg">Digite uma data.</span><span class="textfieldInvalidFormatMsg">Formato inválido, o correto é: DD/MM/AAAA</span></span></td>
</tr>
<tr>
<td width="200" align="right">PRODUTO: </td>
<td width="250" align="left">
  <span id="spryselect1"><select name="produto1" id="produto1" onChange="show()">
    <option value="">SELECIONE O PRODUTO</option>
    <?php
			
				$sql = "select id_produtos, nome_produtos from produtos order by nome_produtos";
				$linha = query($sql);
				while ($select = le_linha($linha))
				{
					if ($select[id_produtos] == $produto)
						$selected = "selected='selected'"; else $selected = '';
						
						
					echo '<option value="'.$select[id_produtos].'" '.$selected.'>'.$select[nome_produtos].'</option>';
				}
			
			?>
  </select></span>
  QUANTIDADE:
  <span id="sprytextfield2"><input name="qt" type="text" size="10" maxlength="10" value="<?php echo $dados[qt_movimento]?>"></span></td>
</tr>
<tr class="tdLabel" style="display:none;" id="label">
<td width="200" align="right">PRODUTO: </td>
<td align="left" id="produto2" style="display:none;">
  <span id="spryselect1"><select name="produto2" id="produto2">
    <option value="">SELECIONE O PRODUTO</option>
    <?php
			
				$sql = "select id_produtos, nome_produtos from produtos order by nome_produtos";
				$linha = query($sql);
				while ($select = le_linha($linha))
				{
					if ($select[id_produtos] == $produto)
						$selected = "selected='selected'"; else $selected = '';
						
						
					echo '<option onclick="show()" value="'.$select[id_produtos].'" '.$selected.'>'.$select[nome_produtos].'</option>';
				}
			
			?>
  </select></span>
  QUANTIDADE:
  <span id="sprytextfield2"><input name="qt" type="text" size="10" maxlength="10" value="<?php echo $dados[qt_movimento]?>"></span></td>
</tr>
<tr>
	<td width="200" align="right">MOVIMENTO: </td>
	<td width="500" colspan="2" align="left"><div id="spryradio1"><input id="RadioGroup1_0" name="mov" type="radio" value="1" <?php echo $radio_1?>> Entrada
	<input id="RadioGroup1_1" name="mov" type="radio" value="2" <?php echo $radio_2?>> Saída <span class="radioRequiredMsg">Escolha o tipo do movimento.</span></div>
	</td>
</tr>
<tr>
	<td width="200" align="right">HISTÓRICO: </td>
	<td width="500" colspan="2" align="left"><textarea name="historico" rows="5" cols="40"><?php echo $dados[historico_movimento]?></textarea></td>
</tr>
<tr>
<td colspan="3" align="center" valign="top"></td></tr></table><BR>
<?php
if ($_GET[id] > 0)
{
	echo '<input id="bt" type="submit" name="bt" value="alterar"> 
	<input id="bt" type="submit" name="bt" value="excluir"> 
	<input id="bt" type="submit" name="bt" value="novo"> ';
}
else
	echo '<input id="bt" type="submit" name="bt" value="inserir"> ';
?>
<input id="bt" type="reset" value="restaurar"></td>
<input type="hidden" name="codigo" value="<?php echo $dados[id_movimento];?>">
</form>
</div>
</div>

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.