Ir para conteúdo

POWERED BY:

Arquivado

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

douglasmesquita

[Resolvido] Valor de campo select

Recommended Posts

Olá pessoal, estou fazendo uma função em javascript para verificar se o campo total está vazio, se é só digitado valores. Depois de verificar isso, preciso calcular o valor do aluguel. Preciso pegar no campo select categoria o valor do campo option para poder fazer o cálculo. No caso, estou testando com o alert para ver se está pegando o valor do campo select, só que aparece undefined. Alguém pode me ajudar?

 

<html>
<head>
<title>Loca 4 Rodas - Reservas</title>
<link rel=stylesheet type="text/css" href="../css/loca.css">
<script language="javascript">
function ehBissexto (ano) {
if ( (ano % 100) == 0 )
ano /= 100;
return (ano % 4) == 0;
}

function verificarData(strData) {
var ultimo;
var v_dia, v_mes, v_ano;
var dias = new Array (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
if ( strData == "" ) {
alert ("Data deve ser preenchida!");
return false;
}
if (strData.charAt(2) != "/" ||
strData.charAt(5) != "/" ) {
alert("Formato da data deve ser DD/MM/AAAA!");
return false;
}
v_ano = parseInt(strData.substring(6));
if ( v_ano < 2011 ) {
alert("Ano (" + v_ano +") inválido, deve ser maior que 2010");
return false;
}
v_mes = parseInt (strData.substring(3,5));
if (v_mes < 01 || v_mes > 12 ) {
alert("Mês (" + v_mes +") inválido, deve ser entre 1 e 12");
return false;
}
ultimo = dias[v_mes - 1];
if ( (v_mes == 02) && ehBissexto(v_ano) )
ultimo++;
v_dia = parseInt( strData.substring(0, 2) );
if ( v_dia < 1 || v_dia > ultimo ) {
alert("Dia (" + v_dia +") inválido, deve ser entre 1 e " + ultimo);
return false;
}
return true;
}

function verificarTotal(f) {
var v_d = f.total.value;
if (v_d.length == 0) {
alert (indexSelect, values_g);
alert("Número de dias dever ser preenchido!");
return false;
}
if (isNaN(v_d)){ 
alert("Número de dias dever ser númerico");
return false;
}
return true;
var indexSelect = document.getElementById("categoria").selectedIndex;
var values_g = f.categoria.options[indexSelect].value;
var aluguel;
if (values_g=0){
  if ((v_d <= 1) || (v_d <= 7)) {
  	aluguel = v_d*60;
  	f.valor.value = aluguel;
alert ("teste")
  }
  else  
  if ((v_d <= 8) || (v_d <= 21)) {
  	aluguel = v_d*54;
  	f.valor.value = aluguel;
  }
  else
aluguel = v_d*48;
  	f.valor.value = aluguel;
}
}	  		
if (values_g=1){
  if ((v_d <= 1) || (v_d <= 7)) {
  	aluguel = v_d*60;
  	f.valor.value = aluguel;
  }
  else  
  if ((v_d <= 8) || (v_d <= 21)) {
  	aluguel = v_d*54;
  	f.valor.value = aluguel;
  }
  else
aluguel = v_d*48;
  	f.valor.value = aluguel;
}
if (values_g=2){
  if ((v_d <= 1) || (v_d <= 7)) {
  	aluguel = v_d*60;
  	f.valor.value = aluguel;
  }
  else  
  if ((v_d <= 8) || (v_d <= 21)) {
  	aluguel = v_d*54;
  	f.valor.value = aluguel;
  }
  else
aluguel = v_d*48;
  	f.valor.value = aluguel;
}
</script>
</head>
<body>
<table width=100%>
<tr>
<td><h1 class=dois><img src="../imagens/roda.gif" class=alinha1>Reservas<img src="../imagens/roda.gif" class=alinha1></h1></td>
<td class=direita><a href="index.html"><img src="../imagens/logo.gif" alt="Loca 4 rodas" border=0></a></td>
</table>
<form method=post>
<table class=tablabel>
<tr>
<td>
<fieldset>
<legend>Dados de Identificação</legend>
<table class=tabLabel>
<tr>
<td class=tabCelLabel width="70"><label for=nome>Nome:</label></td>
<td colspan="3"><input type=text size=90 maxlength=80 name=nome id=nome></td>
</tr>
<tr>
<td class=tabCelLabel><label for=cpf>CPF:</label></td>
<td><input type=text size=40 maxlength=11 name=cpf id=cpf></td>
<td class=tabCelLabel><label for=telefone>Telefone:</label></td>
<td><input type=text size=15 maxlength=11 name=telefone id=telefone></td>
</tr>
<tr>
<td class=tabCelLabel><label for=email>Email:</label></td>
<td><input type=text size=40 maxlength=50 name=email id=email></td>
<td class=tabCelLabel><label for=celular>Celular:</label></td>
<td><input type=text size=15 maxlength=11 name=celular id=celular></td>
</tr>
</table>
</fieldset>
<br>
<fieldset><legend>Dados do Aluguel</legend>
<table class=tabLabel>
<tr>
<td class=tabCelLabel><label for=inicio>Início:</label></td>
<td><input type=text size=10 maxlength=15 name=inicio id=inicio onChange="verificarData(this.value);"></td>
<td><span> por </span><input type=text size=10 maxlength=15 name=total id=total onChange="verificarTotal(this.form);"><span> dias</span></td>
<td class=tabCelLabel><label for=categoria>Categoria:</label></td>
<td><select name=categoria id=categoria>
<option value="-"></option> 
<option value=0>Grupo A</option>
<option value=1>Grupo C</option>
<option value=2>Grupo L</option>
</select>
</td>
</tr>
<tr>
<td colspan=4 class=tabCelLabel><label for=valor>Valor: </label></td>
<td><input type=text size=10 maxlength=11 name=valor id=valor disabled="disabled"></td>
</tr>
</fieldset>
</table>
</td>
</tr>
</table>
<br>
<input type=submit value="Enviar">
<input type=reset value="Limpar">
</form>
</body>
</html>

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.