Ir para conteúdo

POWERED BY:

Arquivado

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

O8oO

Alterar valor pelo campo de texto

Recommended Posts

Olá! Eu estou com uma duvida

 

Eu gostaria que quando eu alterasse o valor de um campo de texto, este valor alterasse automaticamente no campo hidden

 

Por exemplo:

 

 
<form id="form1" name="form1" method="post" action="">
  <label>
    <input type="text" name="quant" id="quant" />
 
<input type="hidden" name="itemQuantity" value="quant" />
 
  </label>
</form>

 

E quando alterasse o valor do "quant" alterasse automaticamente o do "itemQuantity", como proceder?

 

Abr

Compartilhar este post


Link para o post
Compartilhar em outros sites

<form id="form1" name="form1" method="post" action="">

<label>

<input type="text" name="quant" id="quant" />

 

<input type="hidden" name="itemQuantity" id="itemQuantity" value="quant" />

 

</label>

</form>

<script type="text/javascript">

document.getElementById('quant').onkeypress = function(){

document.getElementById('itemQuantity').value = this.value;

}

</script>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Não funcionou :/

 

<form target="pagseguro" style="float:right" action="https://pagseguro.uol.com.br/v2/checkout/cart.html?action=add" method="post">
Quantidade:
<span id="sprytextfield2">
<input name="quant" type="text" id="quant" size="8" />
<span class="textfieldRequiredMsg">Quantos produtos?</span><span class="textfieldInvalidFormatMsg">Invalid format.</span><span class="textfieldMinValueMsg">Coloque ao mínimo 1 produto :).</span><span class="textfieldMaxValueMsg">Tempos <?php echo $row_produto['estoq']; ?> em estoque.</span></span><br />
<input type="hidden" name="receiverEmail" value="eletrica@tambory.com.br" />
<input type="hidden" name="currency" value="BRL" />
<input type="hidden" name="itemId" value="<?php echo $row_home['id']; ?>" />
<input type="hidden" name="itemDescription" value="<?php echo $row_home['nome']; ?>" />
<input type="hidden" name="itemQuantity" id="itemQuantity" />
<input type="hidden" name="itemAmount" value="<?php
$rh = $preco;
if(!strpos($rh,".")&&(strpos($rh,",")))
$rh=substr_replace($rh, ".", strpos($rh, ","), 1);
 
print $rh;
?>" />
 
<input type="hidden" name="shippingType" value="1">
<input type="hidden" name="itemWeight1" value="<?php echo $row_home['frete']; ?>"> 
<?php if($row_home['estoq'] != 0) { ?><input type="image" src="pagseguro.png" name="submit" alt="Pague com PagSeguro - é rápido, grátis e seguro!" /><?php } ?>
</form><script type="text/javascript">
document.getElementById('quant').onkeypress = function(){
    document.getElementById('itemQuantity').value = this.value;
}
</script>

Compartilhar este post


Link para o post
Compartilhar em outros sites


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

</head>

 

<body>

<script src="http://code.jquery.com/jquery-latest.js"></script>

<script type="text/javascript">

$(document).ready(function(){

 

$("#quant").blur(function(){

qtd = $("#quant").val()

$("#itemQuantity").val(qtd);

 

});

 

});

</script>

<input type="text" name="quant" id="quant" />

 

<input type="text" name="itemQuantity" id="itemQuantity" value="50" />

</body>

</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

oi @O8oO, pq vc diz que não funcionou ?

Compartilhar este post


Link para o post
Compartilhar em outros sites

@William Bruno Porque o seu código não havia funcionado. O Código do @Morpheus funcionou,

 

Obrigado aos dois! Valeu mesmo! :)

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.