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

Paul Novitski paul at dandemutande.org
Wed Mar 31 09:55:08 CST 2004


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





More information about the Javascript mailing list