1
I’m new to JS, and I would like to click on a radio and the placeholder would change according to the radio clicked, I did this way but it doesn’t work.
Here is my Modal:
<!-- Button to Open the Modal -->
<form action="/projeto/vendas/" method="post">
<button type="button" class="button-modal btn btn-primary" data-toggle="modal" data-target=".bd-example-modal-xl">Pagar Venda</button>
<!-- The Modal -->
<div class="modal fade bd-example-modal-xl" tabindex="-1" role="dialog" aria-labelledby="myExtraLargeModalLabel" aria-hidden="true">
<div class="div-modal modal-dialog modal-lg">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h2 class="h2-modal modal-title">Formas de Pagamento</h2>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<br />
<table class="payment-methods">
<tr>
<td class="td-modal">
<input type="radio" name="pagamentos_id" id="dinheiro" class="pg pagamentos_id" value="1"/>
<label for="dinheiro" class="labelpag">
<img src="/projeto/img/cash.png" class="imgpag" alt="" >
</label>
<br />
</td>
<td class="td-modal2">
<input type="radio" name="pagamentos_id" id="credito" class="pg pagamentos_id" value="2"/>
<label for="credito" class="labelpag2">
<img src="/projeto/img/card2.png" class="imgpag2">
</label>
</td>
<br />
<td>
<input type="radio" name="pagamentos_id" id="debito" class="pg pagamentos_id" value="3"/>
<label for="debito" class="labelpag2">
<img src="/projeto/img/card.png" class="imgpag2">
</label>
</td>
</tr>
</table>
<table>
<tr>
<td>
<p class="p_pagamento totalpago">Total de Itens:
<?php
if(isset($_SESSION['carrinho'])){
echo count($_SESSION['carrinho']);
?>
<input type="hidden" name="total_produto" id="total_produto" value="<?php echo count($_SESSION['carrinho']); ?>">
<?php
}
?>
</p>
</td>
<td>
<p class="p_pagamento">Total da Venda: R$ <span class="total_venda"></p>
</td>
</tr>
<tr>
<td>
<p class="p_pagamento" id="InputPagamento1"> Total Pago: R$
<input name="total_pago" value="" class="input_pagamento" id="total_pago"></p>
</td>
<td>
<p class="p_pagamento trocopagamento" id="InputPagamento2"> Troco R$
<span id="troco"></span></p>
</td>
</tr>
</table>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>-->
</div>
</div>
</div>
</div>
My Script:
$(document).ready(function () {
$('.pagamentos_id').on('change',function () {
if($(this).val() === '2'){
$('#InputPagamento1').attr({placeholder:"Parcelas:"});
$('#InputPagamento2').attr({placeholder:" "});
}
if($(this).val() ==='3'){
$('#InputPagamento1').attr({placeholder:"Parcelas: "});
$('#InputPagamento2').attr({placeholder:" "});
}
});
});
InputPagamento1
is a<p>
he doesn’t haveplaceholder
, in view of this what you want to change?– novic
I understand, sorry for my lack of knowledge, it would be possible to change the <p>?
– LMT
within the
<p>
has a loose text and a<input>
you want to change the description of the text? ie,Total Pago: R$
forParcelas:
? or place this value oninput
?– novic
That would be right, swap the loose text for Installments:
– LMT