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

Paul Novitski paul at dandemutande.org
Fri Apr 2 11:38:17 CST 2004


Yes, an array of same-named input fields is one way to go, but strikes me 
as being unnecessarily messy in Antony's situation.  Why name the listbox 
the same as the hidden field, if it's really only the hidden field's value 
we want to pass to the server?  Why not name the listbox nothing at all so 
its value doesn't reach the server, and give the hidden field the real 
field name to be passed.

In a case like this, it's sometimes useful to look at the listbox or input 
field as merely a throw-away user interface with no useful value beyond its 
interaction with the user.

One way is to load the listbox with an onChange event that copies its value 
to a hidden field whenever it's actually used.  Another way is to pass one 
or more input values to hidden fields during the submit process.  Either 
way, it separates the user controls from the value-passing fields, which 
can help clarify the situation when user interfaces get really complicated.

It's obviously more elegant to use the same control for both input and 
value-passing, but sometimes complication is warranted.  One circumstance 
might be when I want to tweak, clean up, or convert input values before 
passing them.  Another might be when I have more than one control with the 
same name or purpose but want to pass only one value -- say if I had two 
listboxes for US states and Canadian provinces but wanted to pass only the 
value most recently selected.

Paul


At 05:53 AM 4/2/2004, Chris T wrote:
>Ah.  I didn't know you had a problem with multiple fields by the same name.
>It is entirely possible though to store an array corresponding to your form
>fields instead of hidden fields.
>
>It'd be quite easy. As soon as the page loaded, create an array with as many
>elements as there are disabled form fields on the page. And store the values
>of those fields in the array.
>
>Chris Tifer
>
>
>
>
>
>----- Original Message -----
>From: "Antony Paul" <antonypaul24 at hotmail.com>
>To: "[JavaScript List]" <javascript at LaTech.edu>
>Sent: Thursday, April 01, 2004 11:13 PM
>Subject: Re: [Javascript] How to prevent user from selecting in select box
>
>
> > I acknowledge that you suggested reverting the changes in the onchange()
> > event.
> > The problem with hidden field is when checking the value.length it will
>give
> > error when there is another disabled field with same name .  It was
>possible
> > to avoid this error by assigning a different name to the hidden field. But
> > for that I have to change the JSP coding.
> >
> > Thanks for the suggestions
> > Antony Paul
> >
> > ----- Original Message -----
> > From: "Chris T" <christ at saeweb.com>
> > To: "[JavaScript List]" <javascript at LaTech.edu>
> > Sent: Thursday, April 01, 2004 7:38 PM
> > Subject: Re: [Javascript] How to prevent user from selecting in select box
> >
> >
> > > > 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
> > >
> > > _______________________________________________
> > > 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
>
>_______________________________________________
>Javascript mailing list
>Javascript at LaTech.edu
>https://lists.LaTech.edu/mailman/listinfo/javascript





More information about the Javascript mailing list