Auto complete input text with radio button

Asked

Viewed 58 times

1

As I don’t know much about javascript I need a help to make this script bottom work

What I need is that when selecting a RADIO it autocompletes the input text with the value contained in the corresponding RADIO.

Noting that in the RADIOS Value I put 3 variables separated by a transfer and the variable and be completed can only be the "$value"

$sql56 = $bd->prepare( "SELECT  *  FROM plt where id_paciente = ? AND 
(status = ? OR status = ? ) "  ) or exit( $mysqli->error );
$sql56->bind_param('iss', $id_paciente,$statusplt,$statusplt2); // Coloca o 
valor de $data no lugar da primeira interrogação (?) 
$sql56->execute();
$resultcar56 = $sql56->get_result(); 
while( $row = $resultcar56->fetch_assoc() )
{                  
$valor = $row['valor']; 
$id_plt = $row['id_plt'];
$tipo_servico = $row['tipo_servico'];

echo"<input type='radio' name='id_plt' value='<?php $id_plt-$tipo_servico-$valor?>'>";
echo"<input type='radio' name='id_plt' value='<?php $id_plt-$tipo_servico-$valor?>'>";
echo"<input type='radio' name='id_plt' value='<?php $id_plt-$tipo_servico-$valor?>'>";
}
 <input type="text" name="valor_original" id="valor" placeholder="" value="0" />  

1 answer

2


I think that solves:

var radios = document.querySelectorAll("[name=id_plt]");
for(var x=0; x<radios.length; x++){
   radios[x].onclick = function(){
      document.querySelector("[name=valor_original]").value = this.value.split("-").pop();
   }
}
<input type='radio' name='id_plt' value='a-b-1'>
<input type='radio' name='id_plt' value='c-d-2'>
<input type='radio' name='id_plt' value='e-f-3'>
<input type="text" name="valor_original" id="valor" placeholder="" value="0" /> 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.