Auto complete input text with radio button

1

As I do not know much about javascript I need a help to make this script work down

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

Note that in the Value of the RADIOS I put 3 variables separated by a trasso 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" />  
    
asked by anonymous 15.12.2018 / 03:18

1 answer

2

I think this will solve:

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" /> 
    
15.12.2018 / 03:30