Reputation: 3
I have a company table (databse) with multiple inputs, i need to disable one input field if there is a certain value in another field,
For example:
My input field:
<td><input type=text name=invoice list=invoice maxlength=10 value= " . $row[ "invoice" ] . "></td>
if invoice is not empty or if there is a certain text I need to disable this second input field amstaff:
<td><input type=text name=amstaff list=amstaff maxlength=30 value=" . $row[ "amstaff" ] . "></td>
it is all inserted in PHP code, so javascript or jQuery does not work in here, I already tried many many things on this forum or elsewhere but nothing work for me.
Please any suggestions on how to disable that input field to not be able to change it anymore ? On condition if input field invoice is not empty using php.
Also echo function is not working becouse these input field are inside the echo, this is part of my code:
// output data of each row
while ( $row = $result->fetch_assoc() ) {
echo
"<tr bgcolor='".getcolour($row['status'])."'> <form class=upwo method=post action=update.php>
<td>" . $row[ "id" ] . "</td>
<input type=hidden name=id value= " . $row[ "id" ] . ">
<td class='descrow'>" . $row[ "descr" ] . "</td>
<td>" . $row[ "part" ] . "</td>
<td>" . $row[ "cust" ] . "</td>
<td>" . $row[ "acreg" ] . "</td>
<td>" . $row[ "cat" ] . "</td>
<td>" . date('d M yy', strtotime($row[ "issue" ])) . "</td>
<td>" . date('d M yy', strtotime($row[ "clousure" ])) . "</td>
<td><input type=text name=amstaff list=amstaff maxlength=30 value=" . $row[ "amstaff" ] . "></td>
<datalist id=exstaff>
<option value=Peter Majo></option>
<option value=Dano Adamek></option>
<option value=Rado Janousek></option>
<option value=Niko Ivanics></option>
<option value=Marian Polacik></option>
<option value=Dusan Duben></option>
</datalist>
<td><input type=time name=amtime maxlength=8 value= " . $row[ "amtime" ] . "></td>
<td><input type=text name=exstaff list=exstaff maxlength=30 disabled value= " . $row[ "exstaff" ] . "></td>
<datalist id=exstaff>
<option value=Peter Majo></option>
<option value=Dano Adamek></option>
<option value=Rado Janousek></option>
<option value=Niko Ivanics></option>
<option value=Marian Polacik></option>
<option value=Dusan Duben></option>
</datalist>
<td><input type=time name=extime maxlength=8 value= " . $row[ "extime" ] . "></td>
<td>" . $row[ "summ" ] . "</td>
<td><input type=text name=form maxlength=20 required value= " . $row[ "form" ] . "></td>
<td><input type=text name=invoice list=invoice maxlength=10 required value= " . $row[ "invoice" ] . "></td>
<datalist id=invoice>
<option value=JAN></option>
<option value=FEB></option>
<option value=MAR></option>
<option value=APR></option>
<option value=MAY></option>
<option value=JUN></option>
<option value=JUL></option>
<option value=AUG></option>
<option value=SEP></option>
<option value=OCT></option>
<option value=NOV></option>
<option value=DEC></option>
</datalist>
<td>" . $row[ "status" ] . "</td>
<td><input type=submit value=Update></td>
</form></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
?>
Upvotes: 0
Views: 1281
Reputation: 6684
First simplify your code by echoing jsut the php variables and not all the html: you can do like:
while ( $row = $result->fetch_assoc() ) {
?>
<tr bgcolor="<?php echo getcolour($row['status']); ?>"><form class=upwo method=post action=update.php>
and so on.
Then, to come to your issue (after you have fixed the echo part like above):
<td><input type=text name=amstaff list=amstaff maxlength=30
<?php if($row[ "invoice" ]==""|$row[ "invoice" ]="some_text_here"){
echo " disabled ";
}else{
echo " ";
}
?>
value="<?php echo $row[ "amstaff" ] ?>"></td>
will be what you are looking for
Upvotes: 0