Put radio input disable

Asked

Viewed 78 times

0

Table within the While to create the table with inputs radio dynamic:

$y = 0;
while($rows_cursos = mysqli_fetch_array($resultado_cursos)) {   
$tabela1 .= '<tr>';
$tabela1 .= '<td> <input type="text" readonly="true" size="20" name= "Produto['.$y.']" class= "Produto" value="'.$rows_cursos['Descricao'].'"></td>';
$tabela1 .= '<td> <input type="radio" name= "Sim['.$y.']" value="Ok" required></td>';
$tabela1 .= '<td> <input type="radio" name= "Sim['.$y.']" value="Não Ok" required></td>'
$tabela1 .= '<td> <input type="radio" name= "DataP['.$y.']" value="Ok" required></td>';
$tabela1 .= '<td> <input type="radio" name= "DataP['.$y.']" value="Não Ok" required></td>';
$tabela1 .= '<td> <textarea type="text" class= "Observacao" name="Observacao['.$y.']" rows="2" cols="30"></textarea></td>';
$tabela1 .= '</tr>'; 
$y++;
}

I show in the image the mounted table:

inserir a descrição da imagem aqui

Intended that on the lines where returns the products surrounded in red blocked the inputs radio also surrounded by red, so it is not mandatory to fill in.

  • What is the condition to identify the highlighted records? And you need to block or leave optional?

  • @Anderson Carlos Woss, I really need to block. The condition is, the lines with the following products(x,x,x,x,x), blocks radio input with the name=Datap.

1 answer

1


You can use a ternary operator by filling a string with the value required by default, but with the value disabled when the fields are the ones you want to disable.

$y = 0;
while($rows_cursos = mysqli_fetch_array($resultado_cursos)) {   

$property = ($rows_cursos ["Descricao"]==="x" || $rows_cursos ["Descricao"]==="x2")? "disabled" : "required";

$tabela1 .= '<tr>';
$tabela1 .= '<td> <input type="text" readonly="true" size="20" name= "Produto['.$y.']" class= "Produto" value="'.$rows_cursos['Descricao'].'"></td>';
$tabela1 .= '<td> <input type="radio" name= "Sim['.$y.']" value="Ok" required></td>';
$tabela1 .= '<td> <input type="radio" name= "Sim['.$y.']" value="Não Ok" required></td>'
$tabela1 .= '<td> <input type="radio" name= "DataP['.$y.']" value="Ok" '.$property.'></td>';
$tabela1 .= '<td> <input type="radio" name= "DataP['.$y.']" value="Não Ok" '.$property.'></td>';
$tabela1 .= '<td> <textarea type="text" class= "Observacao" name="Observacao['.$y.']" rows="2" cols="30"></textarea></td>';
$tabela1 .= '</tr>'; 
$y++;
}  

Maybe you can change the field $rows_cursos["Descricao"] for something like $rows_cursos["Id"], but as I do not know the structure I put $rows_cursos["Descricao"] even.

Browser other questions tagged

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