HTML input field disable input but still POST

2019-07-15 07:05发布

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

标签: html webforms
2条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-07-15 07:42

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.

查看更多
一夜七次
3楼-- · 2019-07-15 07:46

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 :)

查看更多
登录 后发表回答