tags:

views:

35

answers:

2

Basically i want a disable text field to show the value stored in a database but i don't want it to be editable by the user.

i've tried using disabled="disabled" but then it no longer POST to my form handler...

Any suggestions?

thanks

+3  A: 

docu:

In this example, the INPUT element is disabled. Therefore, it cannot receive user input nor will its value be submitted with the form.

why do you need the value? then try the readonly-attribute instead of disabled or go for another hiddenfield.

edit:
it's not fully clear to me, if you use asp.net, bu if so, you could just do

<form submitdisabledcontrols="true" runat="server">

you may give it a try :)

Andreas Niedermair
Oh dear how did i miss readonly?!This is exactly what i need thanks alot!
TomFLuff
you're welcome!
Andreas Niedermair
+1  A: 

If you insist on using a disabled field, you can enable it during form submission by handling the form onsubmit event, where you will enable the field and submit the form.

A second option would be to use a readonly field which you may cleverly make look as disabled via CSS.

A third option would be to use a disabled and a hidden field. Rename your disabled field to something irrelevant and use the original field's name for the hidden one.

Take your pick.

Anax
Unfortunately andreas beat you to the reply but thanks for your help.i did think about enabling it on form submission but that seemed a bit tacky.Thanks for the response and good idea about the CSS.
TomFLuff