# How to disable a drop down list after selecting one value

**URL:** <https://www.ruby-forum.com/t/how-to-disable-a-drop-down-list-after-selecting-one-value/185320>\
**Category:** Rails\
**Created:** [March 18, 2010, 6:30am UTC](https://www.ruby-forum.com/t/how-to-disable-a-drop-down-list-after-selecting-one-value/185320 "2010-03-18T06:30:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [March 18, 2010, 6:30am UTC](https://www.ruby-forum.com/t/how-to-disable-a-drop-down-list-after-selecting-one-value/185320/1 "2010-03-18T06:30:40Z")

</div>

my question is i have a drop down list to choose some vales from  
an xml file.after selecting one vaale and saving it will b saved.  
but when i tried to edit that it should be disabled. can any one  
provide solutions

this is ma code fragment

```
    = f.select :name_type, Setting.unroll(:name_type), { :selected

```

=\> (@name.name\_type || “mathew”).to\_sym }, { :style =\>  
“width:300px”,:disabled =\> “true” }

here name\_type is the name of variable declared in d xml file with  
that names.so what should b code 4 disabled

---

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [March 18, 2010, 12:52pm UTC](https://www.ruby-forum.com/t/how-to-disable-a-drop-down-list-after-selecting-one-value/185320/2 "2010-03-18T12:52:24Z")

</div>

On 18 March 2010 05:30, Tony A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> here name\_type is the name of variable declared in d xml file with  
> that names.so what should b code 4 disabled

Assuming there are separate views for new and edit then just disable  
it in the edit view.

Colin

---

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [March 18, 2010, 1:04pm UTC](https://www.ruby-forum.com/t/how-to-disable-a-drop-down-list-after-selecting-one-value/185320/3 "2010-03-18T13:04:52Z")

</div>

Colin L. wrote:

> On 18 March 2010 05:30, Tony A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > here name\_type is ï¿½the ï¿½name ï¿½of variable declared in ï¿½d ï¿½xml file with  
> > that ï¿½names.so ï¿½what ï¿½should b ï¿½code ï¿½ ï¿½4 ï¿½disabled
> 
> Assuming there are separate views for new and edit then just disable  
> it in the edit view.
> 
> Colin

no one view for both

---

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [March 18, 2010, 1:21pm UTC](https://www.ruby-forum.com/t/how-to-disable-a-drop-down-list-after-selecting-one-value/185320/4 "2010-03-18T13:21:06Z")

</div>

On 18 March 2010 12:04, Tony A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> no Â one Â view Â for Â both

If you are using the same view for both how does the view know whether  
to submit a create or an update action?

Colin

---

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [March 18, 2010, 2:11pm UTC](https://www.ruby-forum.com/t/how-to-disable-a-drop-down-list-after-selecting-one-value/185320/5 "2010-03-18T14:11:26Z")

</div>

> this is ma code fragment
> 
> ```
> = f.select :name_type, Setting.unroll(:name_type), { :selected
> 
> ```
> 
> =\> (@name.name\_type || “mathew”).to\_sym }, { :style =\>  
> “width:300px”,:disabled =\> “true” }
> 
> here name\_type is the name of variable declared in d xml file with  
> that names.so what should b code 4 disabled

Try:

= f.select :name\_type, Setting.unroll(:name\_type), { :selected  
=\> (@name.name\_type || “mathew”).to\_sym }, { :style =\>  
“width:300px”,:disabled =\> !@name.new\_record? }

Cheers,

Andy

---

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [March 19, 2010, 6:27am UTC](https://www.ruby-forum.com/t/how-to-disable-a-drop-down-list-after-selecting-one-value/185320/6 "2010-03-19T06:27:35Z")

</div>

great sir.its working now.any way thnks. too got a logic butt  
not workn under some specific conditions. this code beats all of  
those

Andy J. wrote:

> > this is ma code fragment
> > 
> > ```
> > = f.select :name_type, Setting.unroll(:name_type), { :selected
> > 
> > ```
> > 
> > =\> (@name.name\_type || “mathew”).to\_sym }, { :style =\>  
> > “width:300px”,:disabled =\> “true” }
> > 
> > here name\_type is the name of variable declared in d xml file with  
> > that names.so what should b code 4 disabled
> 
> Try:
> 
> = f.select :name\_type, Setting.unroll(:name\_type), { :selected  
> =\> (@name.name\_type || “mathew”).to\_sym }, { :style =\>  
> “width:300px”,:disabled =\> !@name.new\_record? }
> 
> Cheers,
> 
> Andy
