PDA

View Full Version : select text in a disabled <input> text field?



Leeoniya
02-12-2008, 01:19 PM
i need to display data in a disabled text field to prevent editing, but i still want the user to be able to copy to clipboard the data from field. firefox does not allow clipboard manipulation through javascript for valid security concerns. but with the field disabled, i cant even issue an onclick=this.select command.

any suggestions?

thanks,
Leon

GO ILLINI
02-12-2008, 01:45 PM
just have it enabled and have the real "important" value in a hidden input. Then set an onblur for the textbox to set the text back again so they know they cant edit it.

-Adam

Kor
02-12-2008, 02:39 PM
Have you considered using the readonly attribute instead of disabled?


<input type="text" readonly="readonly" value="blah">

Leeoniya
02-12-2008, 10:22 PM
@Kor - readonly would work (alongside an insanely large taborder) except that the :read-only pseudo attribute is only supported in CSS3, while i can use :disabled to style disabled fields.

@GO ILLINI - the overall function is to disable the entire form - so it isnt just one element, it's probably 20-25 per form, it doesnt sit well with me to have that many hidden input fields for this. also my form elements (if enabled) already have a similar behavior because their initial value is the identification of the field and if the user deletes it completely, it gets replaced back in. It will probably confuse the user if the functionality is non-uniform.

thanks, though. I may end up having to deal with the inability to do :disabled clipboard copying

Kor
02-12-2008, 10:42 PM
@Kor - readonly would work (alongside an insanely large taborder) except that the :read-only pseudo attribute is only supported in CSS3, while i can use :disabled to style disabled fields.

You can use only javascript to make an input readonly onload, and play with this attribute later... I see no problem in it...Need an example?

Ultragames
02-12-2008, 11:25 PM
Well Kor that wouldn't fix his CSS problem, because the :disabled class would stop applying once you changed it to readonly. However...

You could set you style to something like this:

my_object:disabled,
my_object.readonly {
/* style */
}

And then use Javasript to change the disableds to readonly when you need to and add the the readonly class name to any of the objects that you change.

Leeoniya
02-12-2008, 11:30 PM
@Ultragames that's just crazy enough to work!, the drawback being that i need to register extra blur and click event handlers on each field.