tags:

views:

118

answers:

2

I would like to display a textbox depending on the value selected in the Html.DropDownList. Is this possible?

+2  A: 

Display where? Show/Hide a textbox depending on value in a drop down?

You could easily achieve this using the change event and jquery. Something like (untested)

$('#dropdownId').change(function(){
  var textbox = $('#textboxId');
  if ($(this).val() == 'foo')
    textbox.hide();
  else
    textbox.show();
});
Fermin
Thank you for your help, that's it working now.
Roslyn
A: 

You'll have to use javascript for that. Add an onchange event for the dropdownlist. Something like:

<%= Html.DropDownList("myList", myData, new { onchange = "showTextBox(this)" }) %>

And your myFunc will look along the lines of:

function showTextBox(item) {
  if(item.value == 'theCorrectValue')
  {
    document.getElementById('myTextBox').style.visibility = 'visible';
  }
}

If you use jQuery, it'll be slightly easier

Razzie