HTML forms - disabled text fields not supposed to pass value

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
maniac9
Forum Commoner
Posts: 55
Joined: Fri Aug 01, 2003 12:27 am
Location: Arkansas, USA
Contact:

HTML forms - disabled text fields not supposed to pass value

Post by maniac9 »

I've noticed something, at least I *think* i have...

I have a form for editing a user profile, and it shows the user their user ID number in a text box that is disabled so they cannot change it. I assumed this value would be passed when the form is submitted, but apparently it is not. Is the only way to get around this to use a hidden field?
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

I haven't noticed it until now! Thanks ;)

Well you will have to do something like this:

Code: Select all

<input type="text" name="email" value="me@myhost.com" disabled="true" /><br />
<input type="hidden" name="email" value="me@myhost.com" /><br />
Cheers,
Scorphus.
maniac9
Forum Commoner
Posts: 55
Joined: Fri Aug 01, 2003 12:27 am
Location: Arkansas, USA
Contact:

Post by maniac9 »

yeah, that works fine - i guess it makes some sense not to pass a field that is disabled, but it interesting now that this is actually the case, at lease with IE5
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

maniac9 wrote:yeah, that works fine - i guess it makes some sense not to pass a field that is disabled, but it interesting now that this is actually the case, at lease with IE5
I think it makes that sense too. Mozilla also doesn't pass a disabled field, but Opera (6.05) does :?! I will test it on more browsers on my Linux box.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

here's a better fix: use the readonly attribute instead

Code: Select all

<input type="text" name="email" value="joe.shmoe@whatever.com" readonly>
try that in your test. tell me if it passes and if it's changable. i think you'll find that unlike the disable which is meant to NOT PASS a value, that this is meant to pass the value one sees

i know from expereince that netscape 7.0, M$IE 5+ and mozilla 1.3.1+ don't pass. i haven't tried on netscape 4.xx but i don't care cuz that wont woork with my site and i make sure ppl know.

fyi: my work around is to set it myself, but then again, on all the instances i use that i know exactly what i want it to be. in the past when i've wanted to block user manipulation i've always used the readonly attribute that has been around since html 3.0
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

• Opera (6.05) pass the disabled and readonly fileds. There is no how change them.

• M$IE, Mozilla, Firebird, Nautilus, Galeon, Konkeror and Lynx pass only the readonly field. There is no how change the disabled and readonly fields.

• Lynx (2.8.4rel.1) lets you change the readonly filed :o!

Cheers,
Scorphus.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

scorphus: then lynx, a gopher browser that very few use, doesn't go to the w3c standard. the standard is that neither one can be changed., that the readonly is passed and disabled is reacted to as if it's not there
Post Reply