[Javascript] How to prevent user from selecting in select box

Chris T christ at saeweb.com
Thu Apr 1 08:08:16 CST 2004


> Using hidden field also is not viable because of javascript validation. It
> will throw error when checking the obj.value.length.

I'm a little confused on this statement.  Why will it throw an error when
checking the length of a value?

> At last I found a solution. Keep the select box enabled. When loading the
> page create a two dimensional array which contains name and values of
select
> boxes to be disabled. In the onchange() event of select box call a
function
> which checks this name in the array and if found it restore its value with
> one found in the array. It works for me.

I think if you look back, you'll see that I suggested something similar
since all js-enabled browsers wound (should) be able to handle. I even
suggested that you alert the user of why it reverted to the original value.

Now if you wanted to take this one step further - at the risk of having the
code rendered useless in some browsers - you can add custom attributes to
that element and read those in the onChange event. Something like
isDisabled="true" originalValue="4" or something along those lines.

Chris Tifer




More information about the Javascript mailing list