views:

41

answers:

3

Hi I have a form that users fill in . Acording to the level of access they have, I want to prevent some of my form being filled in.

If I have a text box I use this onfocus='blur() with a bit of php to check the users privileges .But this does not work for a checkbox. Can anybody suggest how I can prevent a user from checking a checkbox but still have it visible for reference ?

Any help would be much appreciated

Thanks

A: 

Why not disabling it ?

Pierre 303
The reason is some of the users will need to use of this box
Mick
http://www.htmlcodetutorial.com/forms/_INPUT_DISABLED.html
Pierre 303
Disable it only for users that can't use it
Pierre 303
+3  A: 

Give it a disabled attribute. As you currently do, use PHP to check for the user's privilege, and only add the attribute if the user can't use the checkbox. Updated my example with some pseudo-PHP to illustrate:

<?php if (user can access this field) : ?>
<input type="checkbox" name="some-field" value="some-value" />
<?php else: ?>
<input type="checkbox" name="some-field" value="some-value" disabled="disabled" />
<?php endif; ?>
BoltClock
I was going to do that (add a PHP example). Well I suppose you win then; you answered first anyways. +1 :)
Cam
@incrediman: heh, thanks. Though to be more precise I'm *second* while Pierre's answer is the *first* ;)
BoltClock
Also keep in mind that disabling it does not mean you surely recieve it as unchecked on submit. Make sure you also validate the user's rights when you validate/process the form.
Maerlyn
+1  A: 

Try this:

<input type="checkbox" name="mycheckbox" disabled="disabled"> Disabled Option
Cam