tags:

views:

83

answers:

2

Is there a read only property for a checkbox? Because I can still tick on the checkbox even if I have this code, is the read only property only for text box? What's the code if you want the check box to be read-only?

<td><input name="stats1" type="checkbox" id="SSS" readonly="readonly" value="<?php echo $row["STAT"]; ?>" <?php echo $row["STAT"] ? 'checked="checked"' : ''; ?> >SSS</td>
+1  A: 

Try disabled="disabled" instead ;)

henasraf
That works, but this way the value won't be sent to the server anymore. That's the difference with `readonly`.
BalusC
woldn't matter if it's uneditable anyway no? o_O
henasraf
It would matter in for example requestbased confirmation screens or previews.
BalusC
You can avoid that problem by creating a hidden INPUT that represents the value that you want sent back to the server.
Dancrumb
+4  A: 

The readonly attribute on HTML input elements actually means that the value is readonly.

You actually want to make a checkbox uncheckable, in that case grab Javascript:

<input type="checkbox" onclick="return false;">
BalusC
Since js is ultimately unreliable, though, make sure you check on the backend.
D_N
True, that also applies on `readonly` attribute. One can always disable it using JS or tamper the request parameters. Always, always, always check at serverside, regardless of the input flavor.
BalusC