By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,652 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,652 IT Pros & Developers. It's quick & easy.

Override Disabled Property

P: n/a
I would like to override the "disabled" property of a hidden field. When
disabled is set to "true", it would call a function to disable 2 other text
fields on the form. When disabled is set to "false", it would enable those
2 text fields. You should also be able to get the value of it as if it were
a property:

alert(my_hidden_field.disabled);

Is there any way to do this? Many thanks to anyone that can help.
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Kelly Domalik wrote:
I would like to override the "disabled" property of a hidden field. When
You can use script to change the disabled property from 'true' to
'false' and back again.
disabled is set to "true", it would call a function to disable 2 other text
fields on the form. When disabled is set to "false", it would enable those
2 text fields.
Whatever function is changing the disabled value of the element should
also change the others. The intrinsic events for form elements are
listed here:

<URL:http://www.w3.org/TR/html4/interact/forms.html#edef-INPUT>

there is no 'ondisabled' intrinsic event.

You could create your own disable() function that toggles the hidden
field and the other two, then the other function can call your
disable() function so you still have control over what happens when
the control is disabled.

Another way would be to create a listener with setInterval, but that is
not a good idea. You also need to ensure that your page still works
for users with JavaScript disabled or not available.

And a cluey user will be able to re-enable and change the value of the
hidden field if they want, don't depend on the hidden field having any
kind of security just because it's hidden, nor that it won't be
submitted because you disabled it.
You should also be able to get the value of it as if it were
a property:

alert(my_hidden_field.disabled);

Is there any way to do this? Many thanks to anyone that can help.


You can access disabled elements the same way as any other element.
The difference is that the user can't change them using the normal
user interface and they are not successful and so not submitted with a
form, but you can programmatically get and set the value (as can your
user if they want).

--
Rob
Jul 23 '05 #2

P: n/a

Fairly simple:

function toggleState(el,other_el) {
other_el.disabled=el.checked;
other_el.form[other_el.name+'Sub1'].disabled=el.checked;
other_el.form[other_el.name+'Sub2'].disabled=el.checked;
}


click here to disabled:
<input type="checkbox" onclick="toggleState(this,this.form.other)">
<input .... name="other">
<input ... name="otherSub1">
<input ... name="otherSub2">

Danny

On Tue, 21 Jun 2005 17:42:39 -0700, Kelly Domalik <ke*@progplace.com>
wrote:
I would like to override the "disabled" property of a hidden field. When
disabled is set to "true", it would call a function to disable 2 other
text
fields on the form. When disabled is set to "false", it would enable
those
2 text fields. You should also be able to get the value of it as if it
were
a property:

alert(my_hidden_field.disabled);

Is there any way to do this? Many thanks to anyone that can help.


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 23 '05 #3

P: n/a
Jc
Kelly Domalik wrote:
I would like to override the "disabled" property of a hidden field. When
disabled is set to "true", it would call a function to disable 2 other text
fields on the form. When disabled is set to "false", it would enable those
2 text fields.

<snip>

FYI: There is an event you could use to do this called
onpropertychange, AFAIK it only works in IE though, so it probably
isn't very useful. Also, it's probably not the best way to solve the
problem, as some other replies have pointed out.

Refer to:
http://msdn.microsoft.com/workshop/a...ertychange.asp

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.