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

Antony Paul antonypaul24 at hotmail.com
Thu Apr 1 01:38:48 CST 2004


Thanks for all the replies.
I am using IE 6.0.
I tried returning false in onblur() onclick() onchange() events but none
works. Even I change the focus to some other elemet in the onfocus() user
can select an item by holding down the mouse button.
Disabling items on start up and enabling it on submit() may cause trouble.
If the user presses the escape button immediately after clicking submit
button the select box will remain enabled. I tried this and I was able to
cancel submission and it enabled the select box.
Using hidden field also is not viable because of javascript validation. It
will throw error when checking the obj.value.length.
I didn't tried the transparent GIF idea because I could'nt understant it
thoroughly and I dont know how to create a GIF. And this may create problem
since the length of the select box  is varying(Values are from database).
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.

rgds
Antony Paul

----- Original Message -----
From: "Paul Novitski" <paul at dandemutande.org>
To: "[JavaScript List]" <javascript at LaTech.edu>
Sent: Wednesday, March 31, 2004 9:25 PM
Subject: Re: [Javascript] How to prevent user from selecting in select box


> Antony,
>
> I can think of two other techniques that could work:
>
> 1) Intercept the submit event and use Javacsript to pass the value of the
> select list to the server, either by enabling the select list in the
> instant of submission or by copying its value to a hidden field, something
> like:
>
> <select id="TempSelect"><option ...
>
> <input type=hidden id="SelectValue">
>
> <input type=submit onClick="jsSubmit()">
>
> function jsSubmit()
> {
>          // copy the list's selected value to the hidden form field
>          SelectValue.value = TempSelect.options[selectedIndex].value;
>
>          // submit the form
>          this.form.submit();
> }
>
> 2) Position a transparent (or translucent gray) GIF underneath the select
> list, and when you want to disable the list make the gif visible and bring
> it to the front with a larger z-index than the <select tag's z-index.
>
> Paul
>
>
>
> At 05:06 AM 3/31/2004, you wrote:
> >Hi all,
> >     I have a select box which is dynamically generated for editing the
data.
> >Based on a condition it has to be disabled. If I use the disabled
attribute
> >it won't submit the value of the select box and I have to display the
data.
> >I tried onfocus and onclick. But it is not working. Any solutions will be
> >appreciated. I need some way to avert the selection.
> >
> >Antony Paul
> >
> >_______________________________________________
> >Javascript mailing list
> >Javascript at LaTech.edu
> >https://lists.LaTech.edu/mailman/listinfo/javascript
>
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>



More information about the Javascript mailing list