Home All Groups Group Topic Archive Search About

enable/disable text box based on dropdownlist via javascript

Author
19 Mar 2006 10:08 PM
David Thielen
Hi;

I think this is easy - but I haven't been able to figure out exactly what to
do (my attempts have failed). When the value of a DropDownList changes, I
want a javascript function to enable/disable a TextBox based on the new
selected value from this list. How can I do this?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Author
20 Mar 2006 12:43 AM
Axel Dahmen
In your code-behind, add a JavaScript event handler to the DropDownList
control to handle the change event and to do whatever you please:

DropDownList1.Attributes.Add("onchange","document.forms[0].txtBox.value =
'';");

HTH,
Axel Dahmen


------------------
Show quoteHide quote
"David Thielen" <thielen@nospam.nospam> schrieb im Newsbeitrag
news:7471799A-4F35-4274-ADA6-43DAC656EC34@microsoft.com...
> Hi;
>
> I think this is easy - but I haven't been able to figure out exactly what
to
> do (my attempts have failed). When the value of a DropDownList changes, I
> want a javascript function to enable/disable a TextBox based on the new
> selected value from this list. How can I do this?
>
> --
> thanks - dave
> david_at_windward_dot_net
> http://www.windwardreports.com
>
Author
20 Mar 2006 2:45 AM
David Thielen
That's too easy <g>.

I'm still getting used to how to set this up as opposed to setting html
events directly.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com



Show quoteHide quote
"Axel Dahmen" wrote:

> In your code-behind, add a JavaScript event handler to the DropDownList
> control to handle the change event and to do whatever you please:
>
> DropDownList1.Attributes.Add("onchange","document.forms[0].txtBox.value =
> '';");
>
> HTH,
> Axel Dahmen
>
>
> ------------------
> "David Thielen" <thielen@nospam.nospam> schrieb im Newsbeitrag
> news:7471799A-4F35-4274-ADA6-43DAC656EC34@microsoft.com...
> > Hi;
> >
> > I think this is easy - but I haven't been able to figure out exactly what
> to
> > do (my attempts have failed). When the value of a DropDownList changes, I
> > want a javascript function to enable/disable a TextBox based on the new
> > selected value from this list. How can I do this?
> >
> > --
> > thanks - dave
> > david_at_windward_dot_net
> > http://www.windwardreports.com
> >
>
>
>
Author
20 Mar 2006 8:04 AM
Kevin Yu [MSFT]
Hi dave,

To disable the TextBox using javascript, you can use
window.document.getElementById("TextBox1").disabled=true; to achieve. Add a
handler to the dropdownlist.onchange event, and set the desabled value
according to the dropdownlist's value.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."